Home Download Buy Blog Forum Support

Notification of viewport changes?

Notification of viewport changes?

Postby inkytonik on Fri May 10, 2013 3:50 am

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:

Code: Select all
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
inkytonik
 
Posts: 2
Joined: Thu May 03, 2012 10:28 am
Location: Sydney, Australia

Re: Notification of viewport changes?

Postby tito on Fri May 10, 2013 5:21 am

Code: Select all
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, ())
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 851
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Notification of viewport changes?

Postby tito on Fri May 10, 2013 5:22 am

Yeah, a notification would be good.. keep waiting..
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 851
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Notification of viewport changes?

Postby inkytonik on Sat May 11, 2013 9:11 am

Thanks for your response. Yes, some sort of timeout would probably work but it's not ideal.
inkytonik
 
Posts: 2
Joined: Thu May 03, 2012 10:28 am
Location: Sydney, Australia


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests