Add prev/next patchset keys to diff view

Add '<' and '>' keybindings which are used for diffing pairs of
patchsets.  '<' moves to the previous pair, '>' to the next.

Change-Id: I46d24f6e62f113e16be2445a8e52384086c01c8e
This commit is contained in:
James E. Blair 2019-06-18 09:48:05 -07:00
parent 16d0ecb819
commit 77f9fa5602
2 changed files with 35 additions and 0 deletions

View File

@ -81,6 +81,8 @@ RENAME_PROJECT_TOPIC = 'rename project topic'
SELECT_PATCHSETS = 'select patchsets'
NEXT_SELECTABLE = 'next selectable'
PREV_SELECTABLE = 'prev selectable'
NEXT_PATCHSET = 'next patchset'
PREV_PATCHSET = 'prev patchset'
INTERACTIVE_SEARCH = 'interactive search'
# Special:
FURTHER_INPUT = 'further input'
@ -147,6 +149,8 @@ DEFAULT_KEYMAP = {
SELECT_PATCHSETS: 'p',
NEXT_SELECTABLE: 'tab',
PREV_SELECTABLE: 'shift tab',
NEXT_PATCHSET: '>',
PREV_PATCHSET: '<',
INTERACTIVE_SEARCH: 'ctrl s',
}

View File

@ -163,6 +163,10 @@ class BaseDiffView(urwid.WidgetWrap, mywid.Searchable):
"Add an inline comment"),
(keymap.SELECT_PATCHSETS,
"Select old/new patchsets to diff"),
(keymap.NEXT_PATCHSET,
"Diff the next pair of patchsets"),
(keymap.PREV_PATCHSET,
"Diff the previous pair of patchsets"),
(keymap.INTERACTIVE_SEARCH,
"Interactive search"),
]
@ -472,6 +476,12 @@ class BaseDiffView(urwid.WidgetWrap, mywid.Searchable):
if keymap.SELECT_PATCHSETS in commands:
self.openPatchsetDialog()
return None
if keymap.NEXT_PATCHSET in commands:
self.movePatchset(1)
return None
if keymap.PREV_PATCHSET in commands:
self.movePatchset(-1)
return None
if keymap.INTERACTIVE_SEARCH in commands:
self.searchStart()
return None
@ -553,3 +563,24 @@ class BaseDiffView(urwid.WidgetWrap, mywid.Searchable):
self.app.backScreen()
self.old_revision_key, self.new_revision_key = dialog.getSelected()
self._init()
def movePatchset(self, offset):
revisions = []
new = None
with self.app.db.getSession() as session:
change = session.getChange(self.change_key)
for r in change.revisions:
revisions.append((r.key, r.number))
for i, (key, num) in enumerate(revisions):
if key == self.new_revision_key:
new = i
if self.old_revision_key is not None:
new = new + offset
old = new - 1
if new >= len(revisions):
return
if old < 0:
return
self.old_revision_key = revisions[old][0]
self.new_revision_key = revisions[new][0]
self._init()