SHARE
TWEET

RememberPositionOfClosed Sublime Text 3 Plugin

msteen Jul 17th, 2013 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top