Created
March 4, 2012 19:21
-
-
Save agibsonsw/1974433 to your computer and use it in GitHub Desktop.
ST Python to move between last edits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin | |
POSITIONS = {} | |
class LastEditLineCommand(sublime_plugin.TextCommand): | |
posn = 0 | |
def run(self, edit): | |
vid = self.view.id() | |
if not POSITIONS.has_key(vid): return | |
if len(POSITIONS[vid]) <= self.posn + 1: | |
self.posn = 0 | |
self.view.sel().clear() | |
self.view.show(POSITIONS[vid][-(self.posn+1)]) | |
self.view.sel().add(self.view.line(POSITIONS[vid][-(self.posn + 1)])) | |
self.posn = (self.posn + 1) % 5 | |
class CaptureEditing(sublime_plugin.EventListener): | |
def on_modified(self, view): | |
sel = view.sel()[0] | |
vid = view.id() | |
curr_line, _ = view.rowcol(sel.begin()) | |
if not POSITIONS.has_key(vid): | |
POSITIONS[vid] = [curr_line, sel.begin()] | |
elif POSITIONS[vid][0] != curr_line: | |
POSITIONS[vid].append(sel.begin()) | |
POSITIONS[vid][0] = curr_line | |
if len(POSITIONS[vid]) > 6: POSITIONS[vid].pop(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add a shortcut key to run last_edit_line and you can press it to repeatedly cycle to the last five edit positions of the current document/view.