_move_page separated

redraw in the direction of page up/down
This commit is contained in:
ysakamoto
2015-04-21 18:59:21 -05:00
parent f31242dfbd
commit 6025fc24c4

View File

@@ -85,11 +85,13 @@ class Navigator(object):
return valid, redraw return valid, redraw
def move_page(self, direction, n_windows): def move_page(self, direction, n_windows):
"""Move the page down (positive direction) or up (negative """Move page down (positive direction) or up (negative direction)
direction)"""
# top of submission page: act as normal move """
if self.absolute_index < 0:
# top of subreddit/submission page or only one
# submission/reply on the screen: act as normal move
if (self.absolute_index < 0) | (n_windows == 0):
valid, redraw = self.move(direction, n_windows) valid, redraw = self.move(direction, n_windows)
else: else:
# first page # first page
@@ -103,18 +105,26 @@ class Navigator(object):
self.page_index = 0 self.page_index = 0
valid = True valid = True
else: else:
# flip to the direction of movement
if ((direction > 0) & (self.inverted is True))\
| ((direction < 0) & (self.inverted is False)):
self.page_index += (self.step * (n_windows-1))
self.inverted = not self.inverted
self.cursor_index \
= (n_windows-(direction<0)) - self.cursor_index
valid = False valid = False
adj = 0 adj = 0
# check if reached the bottom # check if reached the bottom
while not valid: while not valid:
n_move = n_windows-adj n_move = n_windows - adj
if n_move == 0: if n_move == 0:
break break
self.page_index += n_move*direction self.page_index += n_move * direction
valid = self._is_valid(self.absolute_index) valid = self._is_valid(self.absolute_index)
if not valid: if not valid:
self.page_index -= n_move*direction self.page_index -= n_move * direction
adj += 1 adj += 1
redraw = True redraw = True
@@ -226,13 +236,13 @@ class BasePage(object):
self.clear_input_queue() self.clear_input_queue()
@BaseController.register('n') @BaseController.register('n')
def move_cursor_page_down(self): def move_page_down(self):
self._move_cursor(1, page_ud=True) self._move_page(1)
self.clear_input_queue() self.clear_input_queue()
@BaseController.register('m') @BaseController.register('m')
def move_cursor_page_up(self): def move_page_up(self):
self._move_cursor(-1, page_ud=True) self._move_page(-1)
self.clear_input_queue() self.clear_input_queue()
def clear_input_queue(self): def clear_input_queue(self):
@@ -416,15 +426,9 @@ class BasePage(object):
def _remove_cursor(self): def _remove_cursor(self):
self._edit_cursor(curses.A_NORMAL) self._edit_cursor(curses.A_NORMAL)
def _move_cursor(self, direction, page_ud=False): def _move_cursor(self, direction):
self._remove_cursor() 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: if not valid:
curses.flash() curses.flash()
@@ -434,16 +438,25 @@ class BasePage(object):
self._draw_content() self._draw_content()
self._add_cursor() self._add_cursor()
def _move_page(self, direction):
self._remove_cursor()
valid, redraw = self.nav.move_page(direction,
len(self._subwindows)-1)
if not valid:
curses.flash()
self._draw_content()
# 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
self._add_cursor()
def _edit_cursor(self, attribute=None): def _edit_cursor(self, attribute=None):
# Don't allow the cursor to go below page index 0 # Don't allow the cursor to go below page index 0
if self.nav.absolute_index < 0: if self.nav.absolute_index < 0:
return 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] window, attr = self._subwindows[self.nav.cursor_index]
if attr is not None: if attr is not None:
attribute |= attr attribute |= attr