diff options
Diffstat (limited to 'src/input/model.rs')
| -rw-r--r-- | src/input/model.rs | 21 |
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)] |
