Fixed bug where folding a comment would crash the page.

This commit is contained in:
Michael Lazar
2015-03-15 23:26:30 -07:00
parent 418e11d2aa
commit fd9cbd8841
2 changed files with 19 additions and 14 deletions

View File

@@ -118,12 +118,6 @@ class BasePage(object):
def move_cursor_down(self): def move_cursor_down(self):
self._move_cursor(1) self._move_cursor(1)
def add_cursor(self):
self._edit_cursor(curses.A_REVERSE)
def remove_cursor(self):
self._edit_cursor(curses.A_NORMAL)
def clear_input_queue(self): def clear_input_queue(self):
"Clear excessive input caused by the scroll wheel or holding down a key" "Clear excessive input caused by the scroll wheel or holding down a key"
self.stdscr.nodelay(1) self.stdscr.nodelay(1)
@@ -174,8 +168,7 @@ class BasePage(object):
self.stdscr.erase() self.stdscr.erase()
self._draw_header() self._draw_header()
self._draw_content() self._draw_content()
self._add_cursor()
self.add_cursor()
@staticmethod @staticmethod
def draw_item(window, data, inverted): def draw_item(window, data, inverted):
@@ -243,9 +236,15 @@ class BasePage(object):
self._content_window.refresh() self._content_window.refresh()
def _add_cursor(self):
self._edit_cursor(curses.A_REVERSE)
def _remove_cursor(self):
self._edit_cursor(curses.A_NORMAL)
def _move_cursor(self, direction): def _move_cursor(self, direction):
self.remove_cursor() self._remove_cursor()
valid, redraw = self.nav.move(direction, len(self._subwindows)) valid, redraw = self.nav.move(direction, len(self._subwindows))
if not valid: curses.flash() if not valid: curses.flash()
@@ -253,7 +252,7 @@ class BasePage(object):
# Note: ACS_VLINE doesn't like changing the attribute, so always redraw. # Note: ACS_VLINE doesn't like changing the attribute, so always redraw.
# if redraw: self._draw_content() # if redraw: self._draw_content()
self._draw_content() self._draw_content()
self.add_cursor() self._add_cursor()
def _edit_cursor(self, attribute=None): def _edit_cursor(self, attribute=None):
@@ -269,4 +268,4 @@ class BasePage(object):
for row in range(n_rows): for row in range(n_rows):
window.chgat(row, 0, 1, attribute) window.chgat(row, 0, 1, attribute)
window.refresh() window.refresh()

View File

@@ -69,8 +69,14 @@ class SubmissionPage(BasePage):
self.draw() self.draw()
def toggle_comment(self): def toggle_comment(self):
self.content.toggle(self.nav.absolute_index) current_index = self.nav.absolute_index
self.content.toggle(current_index)
if self.nav.inverted:
# Reset the page so that the bottom is at the cursor position.
# This is a workaround to handle if folding the causes the
# cursor index to go out of bounds.
self.nav.page_index, self.nav.cursor_index = current_index, 0
def refresh_content(self): def refresh_content(self):
@@ -208,4 +214,4 @@ class SubmissionPage(BasePage):
text = Symbol.clean('{score} {comments}'.format(**data)) text = Symbol.clean('{score} {comments}'.format(**data))
win.addnstr(row, 1, text, n_cols, curses.A_BOLD) win.addnstr(row, 1, text, n_cols, curses.A_BOLD)
win.border() win.border()