Skip to content

Commit f5a9d1f

Browse files
committed
Allow nested scrolling of Windows
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.
1 parent 0aa8a97 commit f5a9d1f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/prompt_toolkit/layout/containers.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -2553,33 +2553,33 @@ def _mouse_handler(self, mouse_event: MouseEvent) -> NotImplementedOrNone:
25532553
key binding (no UI invalidate required in that case).
25542554
"""
25552555
if mouse_event.event_type == MouseEventType.SCROLL_DOWN:
2556-
self._scroll_down()
2557-
return None
2556+
return self._scroll_down()
25582557
elif mouse_event.event_type == MouseEventType.SCROLL_UP:
2559-
self._scroll_up()
2560-
return None
2558+
return self._scroll_up()
25612559

25622560
return NotImplemented
25632561

2564-
def _scroll_down(self) -> None:
2562+
def _scroll_down(self) -> "NotImplementedOrNone":
25652563
"Scroll window down."
25662564
info = self.render_info
25672565

25682566
if info is None:
2569-
return
2567+
return NotImplemented
25702568

25712569
if self.vertical_scroll < info.content_height - info.window_height:
25722570
if info.cursor_position.y <= info.configured_scroll_offsets.top:
25732571
self.content.move_cursor_down()
2574-
25752572
self.vertical_scroll += 1
2573+
return None
2574+
2575+
return NotImplemented
25762576

2577-
def _scroll_up(self) -> None:
2577+
def _scroll_up(self) -> "NotImplementedOrNone":
25782578
"Scroll window up."
25792579
info = self.render_info
25802580

25812581
if info is None:
2582-
return
2582+
return NotImplemented
25832583

25842584
if info.vertical_scroll > 0:
25852585
# TODO: not entirely correct yet in case of line wrapping and long lines.
@@ -2588,8 +2588,10 @@ def _scroll_up(self) -> None:
25882588
>= info.window_height - 1 - info.configured_scroll_offsets.bottom
25892589
):
25902590
self.content.move_cursor_up()
2591-
25922591
self.vertical_scroll -= 1
2592+
return None
2593+
2594+
return NotImplemented
25932595

25942596
def get_key_bindings(self) -> KeyBindingsBase | None:
25952597
return self.content.get_key_bindings()

src/prompt_toolkit/layout/controls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def create_content(self, width: int, height: int) -> UIContent:
477477
def get_line(i: int) -> StyleAndTextTuples:
478478
return []
479479

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

482482
def is_focusable(self) -> bool:
483483
return False

0 commit comments

Comments
 (0)