From d56958f61aa4f1716a89f356b97b419bb1736d0c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 25 Feb 2026 19:40:38 +0530 Subject: [PATCH] Cleanup previous PR --- docs/changelog.rst | 2 ++ kitty/keys.py | 4 ++-- kitty/options/utils.py | 11 ++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 1f29112ab..cbbe613b0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -175,6 +175,8 @@ Detailed list of changes - Fix a regression that broke using line numbers with the edit-in-kitty command (:pull:`9346`) +- Key maps: Allow specifying a timeout for multi key mappings and keyboard modes (:pull:`9551`) + - macOS: Fix changes to :opt:`macos_titlebar_color` while in full screen not being applied after exiting fullscreen (:iss:`9350`) - ncurses: Fix ncurses not using dim because it is missing from the sgr property diff --git a/kitty/keys.py b/kitty/keys.py index f1985e4f9..6a7922218 100644 --- a/kitty/keys.py +++ b/kitty/keys.py @@ -124,8 +124,8 @@ class Mappings: from .fast_data_types import add_timer self._cancel_mode_timeout() - self.mode_timeout_timer_id = add_timer(self._on_mode_timeout, mode.timeout, False) - mode.timeout_timer_id = self.mode_timeout_timer_id + self.mode_timeout_timer_id = mode.timeout_timer_id = add_timer( + self._on_mode_timeout, mode.timeout, False) def _cancel_mode_timeout(self) -> None: if self.mode_timeout_timer_id is not None: diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 5db535675..ec777282d 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -1359,20 +1359,18 @@ class KeyboardMode: KeyboardModeMap = dict[str, KeyboardMode] +key_map_option_converters: defaultdict[str, Callable[[str], Any]] = defaultdict(lambda: (lambda x: x)) +key_map_option_converters['timeout'] = float def parse_options_for_map(val: str) -> tuple[KeyMapOptions, str]: expecting_arg = '' ans = KeyMapOptions() - key_map_option_converters: dict[str, Callable[[str], object]] = { - 'timeout': float, - } s = Shlex(val) while (tok := s.next_word())[0] > -1: x = tok[1] if expecting_arg: - convert = key_map_option_converters.get(expecting_arg) - object.__setattr__(ans, expecting_arg, convert(x) if convert else x) + object.__setattr__(ans, expecting_arg, key_map_option_converters[expecting_arg](x)) expecting_arg = '' elif x.startswith('--'): expecting_arg = x[2:] @@ -1382,8 +1380,7 @@ def parse_options_for_map(val: str) -> tuple[KeyMapOptions, str]: if expecting_arg not in allowed_key_map_options: raise KeyError(f'The map option {x} is unknown. Allowed options: {", ".join(allowed_key_map_options)}') if sep == '=': - convert = key_map_option_converters.get(k) - object.__setattr__(ans, k, convert(v) if convert else v) + object.__setattr__(ans, k, key_map_option_converters[k](v)) expecting_arg = '' else: return ans, val[tok[0]:]