Fixed edge case when expanding bottom item the content is cut off.

This commit is contained in:
Michael Lazar
2016-04-15 23:13:05 -07:00
parent 85ea5e6c00
commit 7a2c6ef039
3 changed files with 19 additions and 24 deletions

View File

@@ -92,6 +92,7 @@ class Content(object):
data['type'] = 'MoreComments'
data['count'] = comment.count
data['body'] = 'More comments'
data['hidden'] = True
else:
author = getattr(comment, 'author', '[deleted]')
name = getattr(author, 'name', '[deleted]')
@@ -114,6 +115,7 @@ class Content(object):
data['gold'] = comment.gilded > 0
data['permalink'] = permalink
data['stickied'] = stickied
data['hidden'] = False
return data
@@ -154,6 +156,7 @@ class Content(object):
data['gold'] = sub.gilded > 0
data['nsfw'] = sub.over_18
data['stickied'] = sub.stickied
data['hidden'] = False
data['index'] = None # This is filled in later by the method caller
if sub.url.split('/r/')[-1] == sub.permalink.split('/r/')[-1]:
@@ -317,7 +320,8 @@ class SubmissionContent(Content):
'cache': cache,
'count': count,
'level': data['level'],
'body': 'Hidden'}
'body': 'Hidden',
'hidden': True}
self._comment_data[index:index + len(cache)] = [comment]

View File

@@ -314,21 +314,8 @@ class Page(object):
Loop through submissions and fill up the content page.
"""
# Case 1. Inverted, hiding the bottom element
# Case 2. Inverted, hiding or expanding middle elements
# Case 1+2. Inverted, hiding or expanding elements
# In both cases the screen jumps and is re-aligned with the selected
# item at the bottom of the screen. What we need to do is
# 1.) Grab the height of the top row (subwin.getmaxyx())
# 2.) Draw the page as non inverted, except for the top element. This
# element will be drawn as inverted with the smaller height
# 3.) If expanding and the bottom element also doesn't fit, redraw
# everything inverted as normal.
# 4.) Otherwise, this should ensure that the bottom element is always
# full visible and the cursor doesn't jump lines.
# TODO: If only one comment, add (Not enough space to display)
# TODO: Jumps up one space sometimes
n_rows, n_cols = self.term.stdscr.getmaxyx()
window = self.term.stdscr.derwin(
@@ -376,7 +363,7 @@ class Page(object):
cancel_inverted = True
if cancel_inverted and self.nav.inverted:
# In some special cases we need to make sure that the screen is NOT
# In some cases we need to make sure that the screen is NOT
# inverted. Unfortunately, this currently means drawing the whole
# page over again. Could not think of a better way to pre-determine
# if the content will fill up the page, given that it is dependent

View File

@@ -33,15 +33,19 @@ class SubmissionPage(Page):
current_index = self.nav.absolute_index
self.content.toggle(current_index)
# This logic handles a display edge case after a comment toggle. We want
# to make sure that when we re-draw the page, the cursor stays at its
# current absolute position on the screen. In order to do this, apply
# a fixed offset if, while inverted, we either try to hide the bottom
# comment or toggle any of the middle comments.
if self.nav.inverted:
# Special case when inverted and toggling a comment. We want to
# ensure that when we re-draw the page, the cursor stays at its
# current absolute position. Do this by turning off inversion and
# applying an offset to the top item.
window = self._subwindows[-1][0]
n_rows, _ = window.getmaxyx()
self.nav.flip(len(self._subwindows) - 1)
self.nav.top_item_height = n_rows
data = self.content.get(current_index)
if data['hidden'] or self.nav.cursor_index != 0:
window = self._subwindows[-1][0]
n_rows, _ = window.getmaxyx()
self.nav.flip(len(self._subwindows) - 1)
self.nav.top_item_height = n_rows
@SubmissionController.register(Command('SUBMISSION_EXIT'))
def exit_submission(self):