Advertisement
msteen

RememberPositionOfClosed Sublime Text 3 Plugin

Jul 17th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import sublime, sublime_plugin
  2. from collections import defaultdict
  3.  
  4. class RememberPositionOfClosed(sublime_plugin.EventListener):
  5.     """Remembers the position of closed views, so when they are reopened,
  6.     they can be restored to their previous position."""
  7.  
  8.     # Per window, a stack with the position of closed views.
  9.     closed_cache = defaultdict(list)
  10.  
  11.     def on_window_command(self, window, command_name, args):
  12.         if command_name == 'close':
  13.             self.closed_cache[window.id()].append(window.active_view().viewport_position())
  14.         elif command_name == 'reopen_last_file':
  15.             # The timeout needs to be greater than 0, otherwise setting the viewport position will not work.
  16.             sublime.set_timeout(lambda: self.update_reopened(window), 20)
  17.  
  18.     def update_reopened(self, window):
  19.         window.active_view().set_viewport_position(self.closed_cache[window.id()].pop(), False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement