diff --git a/CHANGELOG.md b/CHANGELOG.md index a1d89d071c..e5ee087437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `tooltip` to Binding https://github.com/Textualize/textual/pull/4859 +### Changed + +- Removed caps_lock and num_lock modifiers https://github.com/Textualize/textual/pull/4861 + ### Fixed - Fix crash when `validate_on` value isn't a set https://github.com/Textualize/textual/pull/4868 diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index 83f84c9295..5e05da7acb 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -275,19 +275,13 @@ def _sequence_to_key_events(self, sequence: str) -> Iterable[events.Key]: key_tokens: list[str] = [] if modifiers: modifier_bits = int(modifiers) - 1 - MODIFIERS = ( - "shift", - "alt", - "ctrl", - "super", - "hyper", - "meta", - "caps_lock", - "num_lock", - ) - for bit, modifier in zip(range(8), MODIFIERS): + # Not convinced of the utility in reporting caps_lock and num_lock + MODIFIERS = ("shift", "alt", "ctrl", "super", "hyper", "meta") + # Ignore caps_lock and num_lock modifiers + for bit, modifier in enumerate(MODIFIERS): if modifier_bits & (1 << bit): key_tokens.append(modifier) + key_tokens.sort() key_tokens.append(key) yield events.Key( diff --git a/src/textual/app.py b/src/textual/app.py index 501c4117e8..126788a0bd 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -870,7 +870,7 @@ def active_bindings(self) -> dict[str, ActiveBinding]: This property may be used to inspect current bindings. Returns: - Active binding information + A dict that maps keys on to binding information. """ return self.screen.active_bindings diff --git a/src/textual/events.py b/src/textual/events.py index d7f5cb11dc..13188d6845 100644 --- a/src/textual/events.py +++ b/src/textual/events.py @@ -290,8 +290,12 @@ def is_printable(self) -> bool: def _key_to_identifier(key: str) -> str: """Convert the key string to a name suitable for use as a Python identifier.""" - if len(key) == 1 and key.isupper(): - key = f"upper_{key.lower()}" + key_no_modifiers = key.split("+")[-1] + if len(key_no_modifiers) == 1 and key_no_modifiers.isupper(): + if "+" in key: + key = f"{key.rpartition('+')[0]}+upper_{key_no_modifiers}" + else: + key = f"upper_{key_no_modifiers}" return key.replace("+", "_").lower()