Added flashes invalid GOTO commands

This commit is contained in:
Michael Lazar
2017-07-23 00:18:45 -04:00
parent ba7efa6bcd
commit 41e10554ae
2 changed files with 35 additions and 17 deletions

View File

@@ -30,8 +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
J : Jump to the next sibling comment
K : Jump to the parent comment
1 : Sort by hot
2 : Sort by top
3 : Sort by rising

View File

@@ -183,30 +183,48 @@ class SubmissionPage(Page):
@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:
"""
Move the cursor up to the comment's parent. If the comment is
top-level, jump to the previous top-level comment.
"""
cursor = self.nav.absolute_index
if cursor > 0:
level = max(self.content.get(cursor)['level'], 1)
while self.content.get(cursor - 1)['level'] >= level:
self._move_cursor(-1)
cur -= 1
cursor -= 1
self._move_cursor(-1)
else:
self.term.flash()
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']
"""
Jump to the next comment that's at the same level as the selected
comment and shares the same parent.
"""
cursor = self.nav.absolute_index
if cursor >= 0:
level = self.content.get(cursor)['level']
try:
move = 1
while self.content.get(cur + move)['level'] > sibling_level:
while self.content.get(cursor + move)['level'] > level:
move += 1
except IndexError:
pass
self.term.flash()
else:
if self.content.get(cur + move)['level'] == sibling_level:
[self._move_cursor(1) for _ in range(move)]
if self.content.get(cursor + move)['level'] == level:
for _ in range(move):
self._move_cursor(1)
else:
self.term.flash()
else:
self.term.flash()
self.clear_input_queue()
def _draw_item(self, win, data, inverted):