forked from jisaacks/GitGutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_gutter_change.py
69 lines (48 loc) · 1.89 KB
/
git_gutter_change.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sublime
import sublime_plugin
try:
from .view_collection import ViewCollection
except (ImportError, ValueError):
from view_collection import ViewCollection
ST3 = int(sublime.version()) >= 3000
def plugin_loaded():
global settings
settings = sublime.load_settings('GitGutter.sublime-settings')
class GitGutterBaseChangeCommand(sublime_plugin.WindowCommand):
def lines_to_blocks(self, lines):
blocks = []
last_line = -2
for line in lines:
if line > last_line + 1:
blocks.append(line)
last_line = line
return blocks
def run(self):
view = self.window.active_view()
inserted, modified, deleted = ViewCollection.diff(view)
inserted = self.lines_to_blocks(inserted)
modified = self.lines_to_blocks(modified)
all_changes = sorted(inserted + modified + deleted)
if all_changes:
row, col = view.rowcol(view.sel()[0].begin())
current_row = row + 1
line = self.jump(all_changes, current_row)
self.window.active_view().run_command("goto_line", {"line": line})
class GitGutterNextChangeCommand(GitGutterBaseChangeCommand):
def jump(self, all_changes, current_row):
if 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)
class GitGutterPrevChangeCommand(GitGutterBaseChangeCommand):
def jump(self, all_changes, current_row):
if 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)
if not ST3:
plugin_loaded()