How to save the current scroll position for all tabs.

SyntaxEditor for WPF Forum

Posted 9 years ago by Mageshwaran Gurusamy
Version: 15.1.0620
Avatar

Hi,

Currently we have developed an editor which supports to view multiple tabs(documents) . when the user opens and starts editing, when he switches to a different tab and come back the earlier tab, the caret resets to first line and first column.

We tried to save last caret position for every document when the selection change happens, but we were not able to save the scroll position.

Tried to save the first position and set it back again in GotFocus method but the First position value does not gets updated always.

We are trying to mock the exact scroll behaviour as in visual studio. Where, each tab remembers the scroll position irrespective of the caret position or the text selection.

Please help us to achieve the same.

Thanks and Regards,

Mageshwaran Gurusamy

Comments (3)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I would need a bit more information about your setup to know how to properly answer your question.  For instance, are you using a separate SyntaxEditor instance on each tab?  If so, it should be remembering all that on its own. 

Or are you using a single SyntaxEditor instance and swapping documents in and out of it.  In that scenario, you would need to store and then later restore the view's Selection.TextRange, FirstVisiblePosition, and FirstVisibleX properties.  If you do those things, it should look the same as before.


Actipro Software Support

Posted 9 years ago by Mageshwaran Gurusamy
Avatar

Hi,

Thanks for the reply.

We are using a single instance of Syntax Editor and dynamically adding documents to it and swapping between them. We are using the approach of saving Selection.TestRange, FirsVisiblePosition and set it back to every docuement on GotFocused event. This works well.

We tried to save the same data for document on MouseWheel event, so that if the user scrolls to a different position and switches to different document, while returning to the last document, the document would show the exact position where the user last seen (Visual Studio behaves like this). But the MouseWheel event is not getting fired.

Kindly verify our approach to use mouse wheel event to achieve what we intent to. If there is any other better approach to achieve the same please suggest us.

Adding to the above approach. Even if the above apporach(mouse wheel) works, suppose the user clicks on the scroll down/up button (below/above slider) to scroll down/up, then the scrolled position may not get stored. We felt, that if there is a scroll changed event, it would be helpfull.

Regards,

Mageshwaran Gurusamy

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I wouldn't recommend trying to save/restore state where you are doing it right now.  There are many types of scenarios that can cause a change in selection, or view position.  I would instead recommend that before you swap in a new document, you store the data at that point.  And after you swap in a new document, you restore the data for that document there.

You could make a property somewhere where you set the document, something along these lines:

public IEditorDocument Document {
  get {
    return editor.Document;
  }
  set {
    // TODO: Save selection, view data here for existing editor.Document
    editor.Document = value
    // TODO: Restore selection, view data here for new editor.Document
  }
}


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.