summaryrefslogtreecommitdiff
path: root/src/input/model.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-07-23 03:47:34 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-07-23 03:47:44 +0300
commite7fc85bfdb51f89488430adbfe5bbced3be79c2f (patch)
treec1c0324f28040c50d0075d6407bdf6ab14d1b8c0 /src/input/model.rs
parent2a20e90a026936d0d5b96823d74e2e4fe13a166f (diff)
fix: preserve kitty printable key releases
refs #1746
Diffstat (limited to 'src/input/model.rs')
-rw-r--r--src/input/model.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/input/model.rs b/src/input/model.rs
index a3e74056..f6072bc6 100644
--- a/src/input/model.rs
+++ b/src/input/model.rs
@@ -9,6 +9,7 @@ pub struct TerminalKey {
pub modifiers: KeyModifiers,
pub kind: crossterm::event::KeyEventKind,
pub shifted_codepoint: Option<u32>,
+ pub is_text_commit: bool,
}
impl TerminalKey {
@@ -18,6 +19,7 @@ impl TerminalKey {
modifiers,
kind: crossterm::event::KeyEventKind::Press,
shifted_codepoint: None,
+ is_text_commit: false,
}
}
@@ -32,6 +34,19 @@ impl TerminalKey {
self
}
+ pub fn as_text_commit(mut self) -> Self {
+ let has_text_only_modifiers = match self.code {
+ KeyCode::Char(ch) if ch.is_ascii_uppercase() => {
+ self.modifiers == KeyModifiers::SHIFT || self.modifiers.is_empty()
+ }
+ KeyCode::Char(_) => self.modifiers.is_empty(),
+ _ => false,
+ };
+ self.is_text_commit =
+ has_text_only_modifiers && self.kind == crossterm::event::KeyEventKind::Press;
+ self
+ }
+
pub fn as_key_event(self) -> KeyEvent {
KeyEvent::new_with_kind(self.code, self.modifiers, self.kind)
}
@@ -43,6 +58,8 @@ impl From<KeyEvent> for TerminalKey {
}
}
+pub(crate) const KITTY_FLAG_REPORT_ALL_KEYS: u16 = 0b0000_1000;
+
#[cfg(not(windows))]
pub fn ime_compatible_keyboard_enhancement_flags() -> KeyboardEnhancementFlags {
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES
@@ -117,6 +134,10 @@ impl KeyboardProtocol {
pub(crate) fn reports_event_types(self) -> bool {
matches!(self, Self::Kitty { flags } if flags & 0b0000_0010 != 0)
}
+
+ pub(crate) fn reports_all_keys(self) -> bool {
+ matches!(self, Self::Kitty { flags } if flags & KITTY_FLAG_REPORT_ALL_KEYS != 0)
+ }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]