For the purposes of this exercise, assume that the two views contain the same number of lines of text. Also, assume that the function otherViewOf(view) returns the other view given one of them.
I've done reasonably well by using this on_selection_modified listener:
- Code: Select all
def on_selection_modified (self, view):
otherview = otherViewOf (view)
if otherview and otherview.file_name ():
viewport = view.viewport_position ()
In other words, if the other view can be determined, get the viewport of the view whose selection changed and use it to set the position of the other view. This works really well as the selection moves around. If the movement causes the viewport to change, the other view tracks it nicely.
However, this method doesn't catch every possible viewport change. E.g., if the user uses the mouse to scroll one of the views, the selection doesn't change and so the handler is not notified.
Is there a way to be notified whenever the viewport of a view changes for any reason? The EventListener API doesn't seem to have such a method and I can't see anything else that would let me tap into it. Does that mean that what I want to do is not possible?