From 4f9ed6546a87112fe73fd8571728bbd0476f3c62 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 30 Dec 2022 08:54:31 +0530 Subject: [PATCH] Pass key events mapped to scroll actions to the program running in the terminal when the terminal is in alternate screen mode Fixes #5839 --- docs/basic.rst | 5 +++++ docs/changelog.rst | 2 ++ kitty/window.py | 52 +++++++++++++++++++++++++++++++--------------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/docs/basic.rst b/docs/basic.rst index 46cdf12c6..db0fa369b 100644 --- a/docs/basic.rst +++ b/docs/basic.rst @@ -27,6 +27,11 @@ Browse scrollback in less :sc:`show_scrollback` Browse last cmd output :sc:`show_last_command_output` (see :ref:`shell_integration`) ========================= ======================= +The scroll actions only take effect when the terminal is in the main screen. +When the alternate screen is active (for example when using a full screen +program like an editor) the key events are instead passed to program running in the +terminal. + Tabs ~~~~~~~~~~~ diff --git a/docs/changelog.rst b/docs/changelog.rst index dab7c7ce9..19c5fb9c2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -53,6 +53,8 @@ Detailed list of changes - Allow using the cwd of the original process for :option:`launch --cwd` (:iss:`5672`) +- Pass key events mapped to scroll actions to the program running in the terminal when the terminal is in alternate screen mode (:iss:`5839`) + - Implement :ref:`edit-in-kitty ` using the new ``kitty-tool`` static executable (:iss:`5546`, :iss:`5630`) - Add an option :opt:`background_tint_gaps` to control background image tinting for window gaps (:iss:`5596`) diff --git a/kitty/window.py b/kitty/window.py index e07517160..5fcd1aac1 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1517,35 +1517,47 @@ class Window: def clear_selection(self) -> None: self.screen.clear_selection() - @ac('sc', 'Scroll up by one line') - def scroll_line_up(self) -> None: + @ac('sc', 'Scroll up by one line when in main screen') + def scroll_line_up(self) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll(SCROLL_LINE, True) + return None + return True - @ac('sc', 'Scroll down by one line') - def scroll_line_down(self) -> None: + @ac('sc', 'Scroll down by one line when in main screen') + def scroll_line_down(self) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll(SCROLL_LINE, False) + return None + return True - @ac('sc', 'Scroll up by one page') - def scroll_page_up(self) -> None: + @ac('sc', 'Scroll up by one page when in main screen') + def scroll_page_up(self) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll(SCROLL_PAGE, True) + return None + return True - @ac('sc', 'Scroll down by one page') - def scroll_page_down(self) -> None: + @ac('sc', 'Scroll down by one page when in main screen') + def scroll_page_down(self) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll(SCROLL_PAGE, False) + return None + return True - @ac('sc', 'Scroll to the top of the scrollback buffer') - def scroll_home(self) -> None: + @ac('sc', 'Scroll to the top of the scrollback buffer when in main screen') + def scroll_home(self) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll(SCROLL_FULL, True) + return None + return True - @ac('sc', 'Scroll to the bottom of the scrollback buffer') - def scroll_end(self) -> None: + @ac('sc', 'Scroll to the bottom of the scrollback buffer when in main screen') + def scroll_end(self) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll(SCROLL_FULL, False) + return None + return True @ac('sc', ''' Scroll to the previous/next shell command prompt @@ -1559,23 +1571,29 @@ class Window: map ctrl+n scroll_to_prompt 1 # jump to next map ctrl+o scroll_to_prompt 0 # jump to last visited ''') - def scroll_to_prompt(self, num_of_prompts: int = -1) -> None: + def scroll_to_prompt(self, num_of_prompts: int = -1) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll_to_prompt(num_of_prompts) + return None + return True - @ac('sc', 'Scroll prompt to the top of the screen, filling screen with empty lines') - def scroll_prompt_to_top(self, clear_scrollback: bool = False) -> None: + @ac('sc', 'Scroll prompt to the top of the screen, filling screen with empty lines, when in main screen') + def scroll_prompt_to_top(self, clear_scrollback: bool = False) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll_until_cursor_prompt() if clear_scrollback: self.screen.clear_scrollback() elif self.screen.scrolled_by > 0: self.screen.scroll(SCROLL_FULL, False) + return None + return True - @ac('sc', 'Scroll prompt to the bottom of the screen, filling in extra lines from the scrollback buffer') - def scroll_prompt_to_bottom(self) -> None: + @ac('sc', 'Scroll prompt to the bottom of the screen, filling in extra lines from the scrollback buffer, when in main screen') + def scroll_prompt_to_bottom(self) -> Optional[bool]: if self.screen.is_main_linebuf(): self.screen.scroll_prompt_to_bottom() + return None + return True @ac('mk', 'Toggle the current marker on/off') def toggle_marker(self, ftype: str, spec: Union[str, Tuple[Tuple[int, str], ...]], flags: int) -> None: