Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested scrolling of Windows #1701

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/prompt_toolkit/layout/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2553,33 +2553,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 @@ -2588,8 +2588,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
2 changes: 1 addition & 1 deletion src/prompt_toolkit/layout/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +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