Skip to content

Commit

Permalink
Use on_clone
Browse files Browse the repository at this point in the history
  • Loading branch information
titoBouzout committed Feb 23, 2012
1 parent 3a68cd7 commit bdc5510
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions BufferScroll.py
Expand Up @@ -25,10 +25,10 @@ def on_load(self, view):
# restore on preview tabs should be fast as posible
self.restore(view)
# overwrite restoration of scroll made by the application
sublime.set_timeout(lambda: self.restore_scroll(view, True), 200)
sublime.set_timeout(lambda: self.restore_scroll(view), 200)

# restore on activated for cloned views
def on_activated(self, view):
def on_clone(self, view):
if view.file_name() != None and view.file_name() != '' and not view.settings().get('is_widget'):
# restore on preview tabs should be fast as posible
self.restore(view)
Expand Down Expand Up @@ -119,10 +119,6 @@ def restore(self, view):
if view.is_loading():
sublime.set_timeout(lambda: self.restore(view), 100)
elif view.file_name():
if view.settings().get('BufferScroll') == self.view_index(view):
return;
else:
view.settings().set('BufferScroll', self.view_index(view))

hash_filename = hashlib.sha1(os.path.normpath(view.file_name().encode('utf-8'))).hexdigest()[:7]
hash_position = hash_filename+':'+self.view_index(view)
Expand Down Expand Up @@ -168,14 +164,10 @@ def restore(self, view):
if int(sublime.version()) >= 2151 and buffer['l']:
view.set_viewport_position(tuple(buffer['l']), False)

def restore_scroll(self, view, force = False):
def restore_scroll(self, view):
if view.is_loading():
sublime.set_timeout(lambda: self.restore_scroll(view), 100)
elif view.file_name():
if view.settings().get('BufferScroll') == self.view_index(view) and force == False:
return;
else:
view.settings().set('BufferScroll', self.view_index(view))

hash_filename = hashlib.sha1(os.path.normpath(view.file_name().encode('utf-8'))).hexdigest()[:7]
hash_position = hash_filename+':'+self.view_index(view)
Expand All @@ -191,4 +183,7 @@ def restore_scroll(self, view, force = False):
view.set_viewport_position(tuple(buffer['l']), False)

def view_index(self, view):
return str(view.window().get_view_index(view) if view.window() and view.window().get_view_index(view) != (0,0) and view.window().get_view_index(view) != (0,-1) else '(0,0)')
return str(view.window().get_view_index(view) if view.window() and view.window().get_view_index(view) != (0,0) and view.window().get_view_index(view) != (0,-1) else '(0,0)')

def _view_index(self, view):
return str(view.window().get_view_index(view) if view.window() else '')

0 comments on commit bdc5510

Please sign in to comment.