Skip to content

Commit

Permalink
Allow nested scrolling of Windows
Browse files Browse the repository at this point in the history
These changes mean that Windows will return NotImplemented when attempting to
scroll beyond their scrollable limits, allowing mouse scroll events to bubble
up to a parent container when a window in a scrollable container is scrolled.
  • Loading branch information
joouha committed Oct 16, 2023
1 parent 490cf90 commit e6aed39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 12 additions & 10 deletions src/prompt_toolkit/layout/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2551,33 +2551,33 @@ def _mouse_handler(self, mouse_event: MouseEvent) -> NotImplementedOrNone:
key binding (no UI invalidate required in that case).
"""
if mouse_event.event_type == MouseEventType.SCROLL_DOWN:
self._scroll_down()
return None
return self._scroll_down()
elif mouse_event.event_type == MouseEventType.SCROLL_UP:
self._scroll_up()
return None
return self._scroll_up()

return NotImplemented

def _scroll_down(self) -> None:
def _scroll_down(self) -> "NotImplementedOrNone":
"Scroll window down."
info = self.render_info

if info is None:
return
return NotImplemented

if self.vertical_scroll < info.content_height - info.window_height:
if info.cursor_position.y <= info.configured_scroll_offsets.top:
self.content.move_cursor_down()

self.vertical_scroll += 1
return None

return NotImplemented

def _scroll_up(self) -> None:
def _scroll_up(self) -> "NotImplementedOrNone":
"Scroll window up."
info = self.render_info

if info is None:
return
return NotImplemented

if info.vertical_scroll > 0:
# TODO: not entirely correct yet in case of line wrapping and long lines.
Expand All @@ -2586,8 +2586,10 @@ def _scroll_up(self) -> None:
>= info.window_height - 1 - info.configured_scroll_offsets.bottom
):
self.content.move_cursor_up()

self.vertical_scroll -= 1
return None

return NotImplemented

def get_key_bindings(self) -> KeyBindingsBase | None:
return self.content.get_key_bindings()
Expand Down
4 changes: 1 addition & 3 deletions src/prompt_toolkit/layout/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,7 @@ def create_content(self, width: int, height: int) -> UIContent:
def get_line(i: int) -> StyleAndTextTuples:
return []

return UIContent(
get_line=get_line, line_count=100**100
) # Something very big.
return UIContent(get_line=get_line, line_count=1)

def is_focusable(self) -> bool:
return False
Expand Down

0 comments on commit e6aed39

Please sign in to comment.