jump directly to parent/sibling comments in submission page
This commit is contained in:
@@ -73,3 +73,5 @@ In submission mode you can view the self text for a submission and browse commen
|
||||
:``o`` or ``ENTER``: Open the comment permalink with your web browser
|
||||
:``SPACE``: Fold the selected comment, or load additional comments
|
||||
:``b``: Display URLs with urlview
|
||||
:``J``: Move cursor to next sibling comment
|
||||
:``K``: Move cursor to parent comment
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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':
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -192,6 +192,22 @@ def test_submission_move_top_bottom(submission_page):
|
||||
assert submission_page.nav.absolute_index == -1
|
||||
|
||||
|
||||
def test_submission_move_sibling_parent(submission_page):
|
||||
|
||||
# Jump to sibling
|
||||
with mock.patch.object(submission_page, 'clear_input_queue'):
|
||||
submission_page.controller.trigger('j')
|
||||
submission_page.controller.trigger('J')
|
||||
assert submission_page.nav.absolute_index == 7
|
||||
|
||||
# Jump to parent
|
||||
with mock.patch.object(submission_page, 'clear_input_queue'):
|
||||
submission_page.controller.trigger('k')
|
||||
submission_page.controller.trigger('k')
|
||||
submission_page.controller.trigger('K')
|
||||
assert submission_page.nav.absolute_index == 0
|
||||
|
||||
|
||||
def test_submission_pager(submission_page, terminal):
|
||||
|
||||
# View a submission with the pager
|
||||
@@ -314,7 +330,7 @@ def test_submission_comment_save(submission_page, terminal, refresh_token):
|
||||
with mock.patch.object(submission_page, 'clear_input_queue'):
|
||||
submission_page.controller.trigger('j')
|
||||
|
||||
# Test save on the coment submission
|
||||
# Test save on the comment submission
|
||||
with mock.patch('rtv.packages.praw.objects.Comment.save') as save, \
|
||||
mock.patch('rtv.packages.praw.objects.Comment.unsave') as unsave:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user