Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sublime, sublime_plugin
- from collections import defaultdict
- class RememberPositionOfClosed(sublime_plugin.EventListener):
- """Remembers the position of closed views, so when they are reopened,
- they can be restored to their previous position."""
- # Per window, a stack with the position of closed views.
- closed_cache = defaultdict(list)
- def on_window_command(self, window, command_name, args):
- if command_name == 'close':
- self.closed_cache[window.id()].append(window.active_view().viewport_position())
- elif command_name == 'reopen_last_file':
- # The timeout needs to be greater than 0, otherwise setting the viewport position will not work.
- sublime.set_timeout(lambda: self.update_reopened(window), 20)
- def update_reopened(self, window):
- window.active_view().set_viewport_position(self.closed_cache[window.id()].pop(), False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement