Skip to content

Commit f1796a3

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 da05f66 commit f1796a3

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
@@ -2567,33 +2567,33 @@ def _mouse_handler(self, mouse_event: MouseEvent) -> "NotImplementedOrNone":
25672567
key binding (no UI invalidate required in that case).
25682568
"""
25692569
if mouse_event.event_type == MouseEventType.SCROLL_DOWN:
2570-
self._scroll_down()
2571-
return None
2570+
return self._scroll_down()
25722571
elif mouse_event.event_type == MouseEventType.SCROLL_UP:
2573-
self._scroll_up()
2574-
return None
2572+
return self._scroll_up()
25752573

25762574
return NotImplemented
25772575

2578-
def _scroll_down(self) -> None:
2576+
def _scroll_down(self) -> "NotImplementedOrNone":
25792577
"Scroll window down."
25802578
info = self.render_info
25812579

25822580
if info is None:
2583-
return
2581+
return NotImplemented
25842582

25852583
if self.vertical_scroll < info.content_height - info.window_height:
25862584
if info.cursor_position.y <= info.configured_scroll_offsets.top:
25872585
self.content.move_cursor_down()
2588-
25892586
self.vertical_scroll += 1
2587+
return None
2588+
2589+
return NotImplemented
25902590

2591-
def _scroll_up(self) -> None:
2591+
def _scroll_up(self) -> "NotImplementedOrNone":
25922592
"Scroll window up."
25932593
info = self.render_info
25942594

25952595
if info is None:
2596-
return
2596+
return NotImplemented
25972597

25982598
if info.vertical_scroll > 0:
25992599
# TODO: not entirely correct yet in case of line wrapping and long lines.
@@ -2602,8 +2602,10 @@ def _scroll_up(self) -> None:
26022602
>= info.window_height - 1 - info.configured_scroll_offsets.bottom
26032603
):
26042604
self.content.move_cursor_up()
2605-
26062605
self.vertical_scroll -= 1
2606+
return None
2607+
2608+
return NotImplemented
26072609

26082610
def get_key_bindings(self) -> Optional[KeyBindingsBase]:
26092611
return self.content.get_key_bindings()

src/prompt_toolkit/layout/controls.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ def create_content(self, width: int, height: int) -> UIContent:
487487
def get_line(i: int) -> StyleAndTextTuples:
488488
return []
489489

490-
return UIContent(
491-
get_line=get_line, line_count=100**100
492-
) # Something very big.
490+
return UIContent(get_line=get_line, line_count=1)
493491

494492
def is_focusable(self) -> bool:
495493
return False

0 commit comments

Comments
 (0)