Sublime Forum

Notification of viewport changes?

#1

I am trying to build a plugin that includes two views that scroll in sync. I.e., if you move the viewport in either one of them, the other one changes to show the same viewport.

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:

def on_selection_modified (self, view): otherview = otherViewOf (view) if otherview and otherview.file_name (): viewport = view.viewport_position () otherview.set_viewport_position (viewport)

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?

thanks,
Tony

0 Likes

#2

def keep_going(): while True: sublime.set_timeout(lambda:the_function_that_checks_and_sync_srcoll_if_apropiated(), 0) time.sleep(0.33) if not 'running_keep_going_loop' in globals(): running_keep_going_loop = True thread.start_new_thread(keep_going, ())

0 Likes

#3

Yeah, a notification would be good… keep waiting…

0 Likes

#4

Thanks for your response. Yes, some sort of timeout would probably work but it’s not ideal.

0 Likes