scrolling 2 editors in tandem

SyntaxEditor for WPF Forum

Posted 3 years ago by Andrew Levine
Version: 19.1.0684
Avatar

I have two SyntaxEditors with slightly different versions of the same text inside, and would like to have the 2nd one scroll to the same place that the user scrolls to in the first one. I can't seem to find the proper events though.

Comments (6)

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

Hi Andrew,

You'd probably want to attach to the editor.ActiveView.TextAreaLayout event.  That event fires whenever that particular IEditorView does a layout and its view lines will be created/measured/arranged.  This could be when scrolling other text changes occur.

The editor.ActiveView.ScrollState property returns the current scroll state in the active view.  So you could effectively sync up scroll states with something like this:

editor2.ActiveView.Scroller.ScrollTo(editor1.ActiveView.ScrollState);

I hope that helps!


Actipro Software Support

Posted 3 years ago by Andrew Levine
Avatar

Thanks, that works great! It doesn't sync up when the user types into the master editor and changes its scroll that way, but otherwise perfect. I can probably subscribe to DocumentChanged for that. -A

Posted 3 years ago by Andrew Levine
Avatar

It works great when only one of the two text editors is hooked up to TextAreaLayout, but when both are hooked in, they have a negative feedback effect on each other. I've tried disconnecting the handlers while one manipulates the other's scroll, but it doesn't seem to happen, maybe because the scrolling is deferred somehow. Is there any way to tell which editor originated the chain of events?

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

Hi Andrew,

Yes in some cases the layout might be deferred. The ScrollTo method doesn't support any external info to be passed in.  Regardless, numerous things might kick off a layout change and could even be combined into one layout pass so I don't think that would be useful.

Could you see which editor contains focus and only scroll the other editor?


Actipro Software Support

Posted 3 years ago by Andrew Levine
Avatar

I think the MouseWheel doesn't need it to be focused to change the scroll position. Plus I don't know what other UI input methods might be seamless like that.

Posted 3 years ago by Andrew Levine
Avatar

Never mind, I just needed to refine my algorithm so the first lines in both editors (original and edited version) matched up correctly, then the deferring isn't such an issue. Thanks!

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

Add Comment

Please log in to a validated account to post comments.