0

I am writing a VSPackage. I need to get the text from the current document in the Visual Studio, edit the text and write it back to the current open document.

When I do this, the current viewport of the document jumps back to the top of the document:

Example Let's say you're working on a document which contains 2000 lines of code, and currently in Visual Studio code editor you see the line numbers 500 to 550. And the cursor is some where at line 700.

After processing the document text, I want the user to see the same line numbers in the code editor and also I want the cursor to stay where it was.

I found some solutions for moving the cursor, however, still couldn't find how to Get and Set the current view port on the active document.

enter image description here

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128

1 Answers1

1

https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.text.editor.iviewscroller(v=vs.120).aspx

Use IViewScroller. It has methods keep a desired span in view, which is most likely what you want, or to scroll by a specified number of lines. Just get its instance with the ViewScroller property of the text view object.

B.K.
  • 9,982
  • 10
  • 73
  • 105