diff --git a/rtv/page.py b/rtv/page.py index 8670982..5f81015 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -90,6 +90,43 @@ class Navigator(object): return valid, redraw + def move_page(self, direction, n_windows): + """Move the page down (positive direction) or up (negative + direction)""" + + # top of submission page: act as normal move + if self.absolute_index < 0: + valid, redraw = self.move(direction, n_windows) + else: + # first page + if self.absolute_index < n_windows and direction < 0: + self.page_index = -1 + self.cursor_index = 0 + self.inverted = False + + # not submission mode: starting index is 0 + if not self._is_valid(self.absolute_index): + self.page_index = 0 + valid = True + else: + valid = False + adj = 0 + # check if reached the bottom + while not valid: + n_move = n_windows-adj + if n_move == 0: + break + + self.page_index += n_move*direction + valid = self._is_valid(self.absolute_index) + if not valid: + self.page_index -= n_move*direction + adj += 1 + + redraw = True + + return valid, redraw + def flip(self, n_windows): "Flip the orientation of the page" @@ -201,6 +238,16 @@ class BasePage(object): self._move_cursor(1) self.clear_input_queue() + @BaseController.register('n') + def move_cursor_page_down(self): + self._move_cursor(1, page_ud=True) + self.clear_input_queue() + + @BaseController.register('m') + def move_cursor_page_up(self): + self._move_cursor(-1, page_ud=True) + self.clear_input_queue() + @BaseController.register('a') def upvote(self): data = self.content.get(self.nav.absolute_index) @@ -460,11 +507,16 @@ class BasePage(object): def _remove_cursor(self): self._edit_cursor(curses.A_NORMAL) - def _move_cursor(self, direction): + def _move_cursor(self, direction, page_ud=False): self._remove_cursor() - valid, redraw = self.nav.move(direction, len(self._subwindows)) + if page_ud: + valid, redraw = self.nav.move_page(direction, + len(self._subwindows)) + else: + valid, redraw = self.nav.move(direction, len(self._subwindows)) + if not valid: curses.flash() @@ -479,6 +531,10 @@ class BasePage(object): if self.nav.absolute_index < 0: return + # Don't allow the cursor to go over the subwindow number + if self.nav.cursor_index >= len(self._subwindows): + self.nav.cursor_index = len(self._subwindows)-1 + window, attr = self._subwindows[self.nav.cursor_index] if attr is not None: attribute |= attr