diff: Add keyboard shortcuts to got to next/previous change

This commit is contained in:
Kovid Goyal
2018-05-09 08:12:40 +05:30
parent 3a1f85cb69
commit a65c807a4a
2 changed files with 24 additions and 7 deletions

View File

@@ -97,6 +97,18 @@ class DiffHandler(Handler):
def num_lines(self):
return self.screen_size.rows - 1
def scroll_to_next_change(self, backwards=False):
if backwards:
r = range(self.scroll_pos - 1, -1, -1)
else:
r = range(self.scroll_pos + 1, len(self.diff_lines))
for i in r:
line = self.diff_lines[i]
if line.is_change_start:
self.scroll_lines(i - self.scroll_pos)
return
self.cmd.bell()
def set_scrolling_region(self):
self.cmd.set_scrolling_region(self.screen_size, 0, self.num_lines - 2)
@@ -191,6 +203,9 @@ class DiffHandler(Handler):
else:
new_ctx += (-1 if text == '-' else 1) * 5
self.change_context_count(new_ctx)
if text in 'np':
self.scroll_to_next_change(backwards=text == 'p')
return
def on_key(self, key_event):
if key_event.type is RELEASE: