From 4eec59728a754ce3ed71edb5147fadf6433a1bc5 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 24 Jan 2024 18:06:41 +0400 Subject: Don't report associated text only for C0/C1 This has a side effect that we'll have text reported for Alt+Shift+T and similar, but only C0/C1 should be excluded and Alt+Shift+T is emitting neither, thus regular `T` will be reported. Fixes #7657. --- CHANGELOG.md | 1 + alacritty/src/input/keyboard.rs | 53 +++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a49ddd0..9b0a086d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - CLI env variables clearing configuration file variables - Vi inline search/semantic selection expanding across newlines +- C0 and C1 codes being emitted in associated text when using kitty keyboard ### Changed diff --git a/alacritty/src/input/keyboard.rs b/alacritty/src/input/keyboard.rs index d939c3dc..1df1b13b 100644 --- a/alacritty/src/input/keyboard.rs +++ b/alacritty/src/input/keyboard.rs @@ -275,11 +275,18 @@ fn build_sequence(key: KeyEvent, mods: ModifiersState, mode: TermMode) -> Vec (payload, terminator), @@ -289,10 +296,7 @@ fn build_sequence(key: KeyEvent, mods: ModifiersState, mode: TermMode) -> Vec Vec Option { + fn try_build_textual( + &self, + key: &KeyEvent, + associated_text: Option<&str>, + ) -> Option { let character = match key.logical_key.as_ref() { Key::Character(character) => character, _ => return None, @@ -374,10 +376,7 @@ impl SequenceBuilder { }; Some(SequenceBase::new(payload.into(), SequenceTerminator::Kitty)) - } else if self.kitty_encode_all - && self.mode.contains(TermMode::REPORT_ASSOCIATED_TEXT) - && key.text.is_some() - { + } else if self.kitty_encode_all && associated_text.is_some() { // Fallback when need to report text, but we don't have any key associated with this // text. Some(SequenceBase::new("0".into(), SequenceTerminator::Kitty)) @@ -644,3 +643,11 @@ impl From for SequenceModifiers { modifiers } } + +/// Check whether the `text` is `0x7f`, `C0` or `C1` control code. +fn is_control_character(text: &str) -> bool { + // 0x7f (DEL) is included here since it has a dedicated control code (`^?`) which generally + // does not match the reported text (`^H`), despite not technically being part of C0 or C1. + let codepoint = text.bytes().next().unwrap(); + text.len() == 1 && (codepoint < 0x20 || (0x7f..=0x9f).contains(&codepoint)) +} -- cgit v1.2.3-54-g00ecf