Skip to content

Commit e6aed39

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 490cf90 commit e6aed39

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/prompt_toolkit/layout/containers.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -2551,33 +2551,33 @@ def _mouse_handler(self, mouse_event: MouseEvent) -> NotImplementedOrNone:
25512551
key binding (no UI invalidate required in that case).
25522552
"""
25532553
if mouse_event.event_type == MouseEventType.SCROLL_DOWN:
2554-
self._scroll_down()
2555-
return None
2554+
return self._scroll_down()
25562555
elif mouse_event.event_type == MouseEventType.SCROLL_UP:
2557-
self._scroll_up()
2558-
return None
2556+
return self._scroll_up()
25592557

25602558
return NotImplemented
25612559

2562-
def _scroll_down(self) -> None:
2560+
def _scroll_down(self) -> "NotImplementedOrNone":
25632561
"Scroll window down."
25642562
info = self.render_info
25652563

25662564
if info is None:
2567-
return
2565+
return NotImplemented
25682566

25692567
if self.vertical_scroll < info.content_height - info.window_height:
25702568
if info.cursor_position.y <= info.configured_scroll_offsets.top:
25712569
self.content.move_cursor_down()
2572-
25732570
self.vertical_scroll += 1
2571+
return None
2572+
2573+
return NotImplemented
25742574

2575-
def _scroll_up(self) -> None:
2575+
def _scroll_up(self) -> "NotImplementedOrNone":
25762576
"Scroll window up."
25772577
info = self.render_info
25782578

25792579
if info is None:
2580-
return
2580+
return NotImplemented
25812581

25822582
if info.vertical_scroll > 0:
25832583
# TODO: not entirely correct yet in case of line wrapping and long lines.
@@ -2586,8 +2586,10 @@ def _scroll_up(self) -> None:
25862586
>= info.window_height - 1 - info.configured_scroll_offsets.bottom
25872587
):
25882588
self.content.move_cursor_up()
2589-
25902589
self.vertical_scroll -= 1
2590+
return None
2591+
2592+
return NotImplemented
25912593

25922594
def get_key_bindings(self) -> KeyBindingsBase | None:
25932595
return self.content.get_key_bindings()

src/prompt_toolkit/layout/controls.py

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

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

484482
def is_focusable(self) -> bool:
485483
return False

0 commit comments

Comments
 (0)