jump directly to parent/sibling comments in submission page

This commit is contained in:
woorst
2017-07-19 10:13:17 -05:00
parent 47239b9bca
commit 2c3b00b79a
5 changed files with 52 additions and 2 deletions

View File

@@ -30,6 +30,8 @@ https://github.com/michael-lazar/rtv
m : Move up one page
gg : Jump to the first post
G : Jump to the last post
J : Jump to next sibling comment
K : Jump to parent comment
1 : Sort by hot
2 : Sort by top
3 : Sort by rising

View File

@@ -181,6 +181,34 @@ class SubmissionPage(Page):
else:
self.term.flash()
@PageController.register(Command('SUBMISSION_GOTO_PARENT'))
def move_parent_up(self):
cur = self.nav.absolute_index
if cur > 0:
child_level = self.content.get(cur)['level']
while self.content.get(cur-1)['level'] >= 1 \
and self.content.get(cur-1)['level'] >= child_level:
self._move_cursor(-1)
cur -= 1
self._move_cursor(-1)
self.clear_input_queue()
@PageController.register(Command('SUBMISSION_GOTO_SIBLING'))
def move_sibling_next(self):
cur = self.nav.absolute_index
if cur in range(self.content.range[1]):
sibling_level = self.content.get(cur)['level']
try:
move = 1
while self.content.get(cur + move)['level'] > sibling_level:
move += 1
except IndexError:
pass
else:
if self.content.get(cur + move)['level'] == sibling_level:
[self._move_cursor(1) for _ in range(move)]
self.clear_input_queue()
def _draw_item(self, win, data, inverted):
if data['type'] == 'MoreComments':

View File

@@ -128,6 +128,8 @@ SUBMISSION_POST = c
SUBMISSION_EXIT = h, <KEY_LEFT>
SUBMISSION_OPEN_IN_PAGER = l, <KEY_RIGHT>
SUBMISSION_OPEN_IN_URLVIEWER = b
SUBMISSION_GOTO_PARENT = K
SUBMISSION_GOTO_SIBLING = J
; Subreddit page
SUBREDDIT_SEARCH = f