Permalink
Browse files

added keyboard shortcuts to go through changed lines #11

`Ctrl+Shift+Page Up` to go up, and `Ctrl+Shift+Page Down` to go down
  • Loading branch information...
1 parent 7105f1d commit e6289c3aec7aae62cd32608ac0086e71f4d0dd58 Aleksandr Gornostal committed Jul 4, 2012
Showing with 74 additions and 3 deletions.
  1. +4 −1 Default (Linux).sublime-keymap
  2. +4 −1 Default (OSX).sublime-keymap
  3. +4 −1 Default (Windows).sublime-keymap
  4. +60 −0 Modific.py
  5. +2 −0 README.md
@@ -1,5 +1,8 @@
[
{ "keys": ["ctrl+alt+c"], "command": "show_original_part" },
{ "keys": ["ctrl+alt+r"], "command": "replace_modified_part" },
- { "keys": ["ctrl+alt+d"], "command": "show_diff" }
+ { "keys": ["ctrl+alt+d"], "command": "show_diff" },
+
+ { "keys": ["ctrl+shift+pageup"], "command": "jump_between_changes", "args": {"direction": "prev"} },
+ { "keys": ["ctrl+shift+pagedown"], "command": "jump_between_changes", "args": {"direction": "next"} }
]
@@ -1,5 +1,8 @@
[
{ "keys": ["ctrl+super+c"], "command": "show_original_part" },
{ "keys": ["ctrl+super+r"], "command": "replace_modified_part" },
- { "keys": ["ctrl+super+d"], "command": "show_diff" }
+ { "keys": ["ctrl+super+d"], "command": "show_diff" },
+
+ { "keys": ["ctrl+shift+pageup"], "command": "jump_between_changes", "args": {"direction": "prev"} },
+ { "keys": ["ctrl+shift+pagedown"], "command": "jump_between_changes", "args": {"direction": "next"} }
]
@@ -1,5 +1,8 @@
[
{ "keys": ["ctrl+alt+c"], "command": "show_original_part" },
{ "keys": ["ctrl+alt+r"], "command": "replace_modified_part" },
- { "keys": ["ctrl+alt+d"], "command": "show_diff" }
+ { "keys": ["ctrl+alt+d"], "command": "show_diff" },
+
+ { "keys": ["ctrl+shift+pageup"], "command": "jump_between_changes", "args": {"direction": "prev"} },
+ { "keys": ["ctrl+shift+pagedown"], "command": "jump_between_changes", "args": {"direction": "next"} }
]
View
@@ -413,3 +413,63 @@ def on_activated(self, view):
def on_post_save(self, view):
view.run_command('hl_changes')
+
+
+class JumpBetweenChangesCommand(DiffCommand, sublime_plugin.TextCommand):
+ def run(self, edit, direction='next'):
+ lines = self._get_lines()
+ if not lines:
+ return
+
+ if direction == 'prev':
+ lines.reverse()
+
+ (current_line, col) = self.view.rowcol(self.view.sel()[0].begin())
+ current_line += 1
+ jump_to = None
+ for line in lines:
+ if direction == 'next' and current_line < line:
+ jump_to = line
+ break
+ if direction == 'prev' and current_line > line:
+ jump_to = line
+ break
+
+ if not jump_to:
+ jump_to = lines[0]
+
+ self.goto_line(edit, jump_to)
+
+ def goto_line(self, edit, line):
+ # Convert from 1 based to a 0 based line number
+ line = int(line) - 1
+
+ # Negative line numbers count from the end of the buffer
+ if line < 0:
+ lines, _ = self.view.rowcol(self.view.size())
+ line = lines + line + 1
+
+ pt = self.view.text_point(line, 0)
+
+ self.view.sel().clear()
+ self.view.sel().add(sublime.Region(pt))
+
+ self.view.show(pt)
+
+ def _get_lines(self):
+ diff_parser = DiffParser.instance
+ if not diff_parser:
+ return
+
+ (inserted, changed, deleted) = diff_parser.get_lines_to_hl()
+ lines = list(set(inserted + changed + deleted))
+ lines.sort()
+
+ prev = None
+ ret_lines = []
+ for line in lines:
+ if prev != line - 1:
+ ret_lines.append(line)
+ prev = line
+
+ return ret_lines
View
@@ -54,6 +54,8 @@ Features / Usage
This command reverts modifications if your cursor stays on modified line (or if on group of lines, then whole group will be reverted)
+**Jump between changes** `Ctrl+Shift+Page Up(Down)`
+
For those who expected to see a clone of Netbeans feature - unfortunately, with existing ST2 API that is impossible :(
Configuring

0 comments on commit e6289c3

Please sign in to comment.