diff options
| author | Edmund-a7 <J18115025119@163.com> | 2026-04-07 20:57:51 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-07 20:57:51 +0800 |
| commit | 53bb02b53720d00464843fa565850cbdef35aaad (patch) | |
| tree | 803d8b81b49ec8f54a82ac61b28763123e6e1e85 /src/input/encode.rs | |
| parent | 78fc0721a3d014fe96e778c6bb452cfdfbe67603 (diff) | |
| parent | 34bc876c665c0b5560766bc89dd6536aefce2cb7 (diff) | |
Merge pull request #1 from Edmund-a7/fix/ime-input-support
fix: support IME input for Chinese and other UTF-8 characters
Diffstat (limited to 'src/input/encode.rs')
| -rw-r--r-- | src/input/encode.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/input/encode.rs b/src/input/encode.rs index 4aa68e17..1311d4a0 100644 --- a/src/input/encode.rs +++ b/src/input/encode.rs @@ -309,19 +309,31 @@ fn kitty_modifier(mods: KeyModifiers) -> u32 { } fn encode_text_input(key: &TerminalKey) -> Option<Vec<u8>> { + let ch = match key.code { + KeyCode::Char(ch) => ch, + _ => return None, + }; + + if key.modifiers.is_empty() { + match key.kind { + crossterm::event::KeyEventKind::Press | crossterm::event::KeyEventKind::Repeat => { + let mut buf = [0u8; 4]; + return Some(ch.encode_utf8(&mut buf).as_bytes().to_vec()); + } + crossterm::event::KeyEventKind::Release => return Some(Vec::new()), + } + } + if key.modifiers != KeyModifiers::SHIFT { return None; } - let ch = match key.code { - KeyCode::Char(ch) => shifted_text_char(key, ch)?, - _ => return None, - }; + let shifted_ch = shifted_text_char(key, ch)?; match key.kind { crossterm::event::KeyEventKind::Press | crossterm::event::KeyEventKind::Repeat => { let mut buf = [0u8; 4]; - Some(ch.encode_utf8(&mut buf).as_bytes().to_vec()) + Some(shifted_ch.encode_utf8(&mut buf).as_bytes().to_vec()) } crossterm::event::KeyEventKind::Release => Some(Vec::new()), } |
