forked from jisaacks/GitGutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_gutter_jump_to_changes.py
37 lines (29 loc) · 1.32 KB
/
git_gutter_jump_to_changes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- coding: utf-8 -*-
class GitGutterJumpToChanges(object):
def __init__(self, git_handler):
self.git_handler = git_handler
def goto_line(self, jump_func, all_changes):
if all_changes:
view = self.git_handler.view
row, col = view.rowcol(view.sel()[0].begin())
current_row = row + 1
line = jump_func(all_changes, current_row)
view.run_command("goto_line", {"line": line})
def jump_to_next_change(self):
self.goto_line(self.next_jump, self.git_handler.diff_changed_blocks())
def jump_to_prev_change(self):
self.goto_line(self.prev_jump, self.git_handler.diff_changed_blocks())
def next_jump(self, all_changes, current_row):
if self.git_handler.settings.get('next_prev_change_wrap', True):
default = all_changes[0]
else:
default = all_changes[-1]
return next((change for change in all_changes
if change > current_row), default)
def prev_jump(self, all_changes, current_row):
if self.git_handler.settings.get('next_prev_change_wrap', True):
default = all_changes[-1]
else:
default = all_changes[0]
return next((change for change in reversed(all_changes)
if change < current_row), default)