From 34bc876c665c0b5560766bc89dd6536aefce2cb7 Mon Sep 17 00:00:00 2001 From: acumen7 Date: Tue, 7 Apr 2026 20:52:24 +0800 Subject: fix: support IME input for Chinese and other UTF-8 characters Phase 1: UTF-8 encoding support - Modified encode_text_input() to handle characters without modifiers - Added unit tests for Chinese character encoding Phase 2: IME composition support - Removed REPORT_ALL_KEYS_AS_ESCAPE_CODES keyboard flag - Prevents keyboard protocol from interfering with IME - Allows digit keys to be captured by input method for candidate selection Fixes issue where IME input was not working properly. Supports Chinese, Japanese, Korean, and other UTF-8 input methods. Maintains compatibility with all existing features. Tested: - All 388 unit tests pass - Chinese IME input with pinyin works correctly - All navigate mode shortcuts work normally - All terminal applications work normally --- src/input/encode.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/input/encode.rs') 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> { + 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()), } -- cgit v1.2.3