Skip to content

Commit

Permalink
Fix scolling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
joouha committed Aug 29, 2022
1 parent ba5f767 commit 161cb92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Added
Fixed
=====

- Prevent jumping when scrollig if document is less than one page long
- Fixed issue with range sliders which caused a crash on notebook load

----
Expand Down
42 changes: 23 additions & 19 deletions euporie/core/widgets/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,25 +518,29 @@ def write_to_screen(
# Set this to false again, allowing us to scroll the cursor out of view
self.scroll_to_cursor = False

# Prevent overscrolling at the top of the document
heights_above = sum(
self.get_child_render_info(index).height
for index in range(self._selected_slice.start)
)
overscroll = heights_above - self.selected_child_position
if overscroll < 0:
self.selected_child_position += overscroll
elif overscroll > 0:
heights_below = sum(
# Ensure unrendered cells have at least some height
self.get_child_render_info(index).height or 1
for index in range(self._selected_slice.start, len(self._children))
)
underscroll = (
self.selected_child_position + heights_below - available_height
)
if underscroll < 0:
self.selected_child_position -= underscroll
# Adjust scrolling offset
heights = [
# Ensure unrendered cells have at least some height
self.get_child_render_info(index).height or 1
for index in range(len(self._children))
]
heights_above = sum(heights[: self._selected_slice.start])
# Do not allow scrolling if there is no overflow
if sum(heights) < available_height:
self.selected_child_position = heights_above
else:
# Prevent overscrolling at the top of the document
overscroll = heights_above - self.selected_child_position
if overscroll < 0:
self.selected_child_position += overscroll
# Prevent underscrolling at the bottom
elif overscroll > 0:
heights_below = sum(heights[self._selected_slice.start :])
underscroll = (
self.selected_child_position + heights_below - available_height
)
if underscroll < 0:
self.selected_child_position -= underscroll

# Blit first selected child and those below it that are on screen
line = self.selected_child_position
Expand Down

0 comments on commit 161cb92

Please sign in to comment.