From b0b51678e4b30b81f3909123717673564a2ca97b Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sat, 6 Jul 2024 10:38:51 +0900 Subject: [PATCH 1/2] build: Bump Corrosion to v0.5 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae1d14b7..a2d7a94e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,7 +93,7 @@ if(WITH_RUST) FetchContent_Declare( Corrosion GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git - GIT_TAG be76480232216a64f65e3b1d9794d68cbac6c690 # v0.4.5 + GIT_TAG 64289b1d79d6d19cd2e241db515381a086bb8407 # v0.5 FIND_PACKAGE_ARGS ) FetchContent_MakeAvailable(Corrosion) From e95e79edade76f55ea940457c873a4aa98bbec9c Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sat, 6 Jul 2024 14:22:26 +0900 Subject: [PATCH 2/2] fix(editor): printable non A-Z chars should output symbols in pinyin --- src/editor/keyboard/mod.rs | 11 +++++++++++ src/editor/mod.rs | 26 ++++++++++++++++++++++++++ src/editor/zhuyin_layout/pinyin.rs | 3 +++ tests/test-bopomofo.c | 23 +++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/src/editor/keyboard/mod.rs b/src/editor/keyboard/mod.rs index 421e836e..73142a11 100644 --- a/src/editor/keyboard/mod.rs +++ b/src/editor/keyboard/mod.rs @@ -230,6 +230,10 @@ impl KeyCode { _ => None, } } + #[rustfmt::skip] + pub const fn is_atoz(&self) -> bool { + matches!(self, A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z) + } } use KeyCode::*; @@ -248,6 +252,13 @@ pub struct KeyEvent { pub modifiers: Modifiers, } +impl KeyEvent { + pub(crate) fn is_printable(&self) -> bool { + // FIXME refactor + self.unicode != '�' + } +} + impl fmt::Display for KeyEvent { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "key-{:?}-{:?}-{}-", self.index, self.code, self.unicode)?; diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 62028714..11fbdfb2 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -1027,6 +1027,32 @@ impl State for Entering { shared.com.insert(Symbol::from(symbol)); return self.spin_absorb(); } + if ev.is_printable() { + match shared.options.character_form { + CharacterForm::Halfwidth => { + if shared.com.is_empty() { + // FIXME we should ignore these keys if pre-edit is empty + shared.commit_buffer.clear(); + shared.commit_buffer.push(ev.unicode); + return self.spin_commit(); + } else { + shared.com.insert(Symbol::from(ev.unicode)); + return self.spin_absorb(); + } + } + CharacterForm::Fullwidth => { + let char_ = full_width_symbol_input(ev.unicode).unwrap(); + if shared.com.is_empty() { + shared.commit_buffer.clear(); + shared.commit_buffer.push(char_); + return self.spin_commit(); + } else { + shared.com.insert(Symbol::from(char_)); + return self.spin_absorb(); + } + } + } + } self.spin_bell() } LanguageMode::English => match shared.options.character_form { diff --git a/src/editor/zhuyin_layout/pinyin.rs b/src/editor/zhuyin_layout/pinyin.rs index 9351ee7c..fa492ce7 100644 --- a/src/editor/zhuyin_layout/pinyin.rs +++ b/src/editor/zhuyin_layout/pinyin.rs @@ -71,6 +71,9 @@ impl Pinyin { impl SyllableEditor for Pinyin { fn key_press(&mut self, key: KeyEvent) -> KeyBehavior { + if self.key_seq.is_empty() && !key.code.is_atoz() { + return KeyBehavior::KeyError; + } if ![ KeyCode::Space, KeyCode::N1, diff --git a/tests/test-bopomofo.c b/tests/test-bopomofo.c index e95db7f8..de3bccf5 100644 --- a/tests/test-bopomofo.c +++ b/tests/test-bopomofo.c @@ -2018,6 +2018,28 @@ void test_KB_HANYU() chewing_delete(ctx); } +void test_KB_HANYU_direct_symbol_output() +{ + ChewingContext *ctx; + + ctx = chewing_new(); + start_testcase(ctx, fd); + + chewing_set_KBType(ctx, KB_HANYU_PINYIN); + + type_keystroke_by_string(ctx, "pin yin 123 mo2shi4"); + ok_preedit_buffer(ctx, "拼音 123 模式"); + chewing_clean_preedit_buf(ctx); + + chewing_set_KBType(ctx, KB_HANYU_PINYIN); + chewing_set_ShapeMode(ctx, FULLSHAPE_MODE); + + type_keystroke_by_string(ctx, "pin yin 123 mo2shi4"); + ok_preedit_buffer(ctx, "拼音 123 模式"); + chewing_clean_preedit_buf(ctx); + + chewing_delete(ctx); +} void test_KB_THL() { @@ -2162,6 +2184,7 @@ void test_KB() test_KB_COLEMAK_DH_ORTH(); test_KB_HANYU(); + test_KB_HANYU_direct_symbol_output(); test_KB_THL(); test_KB_MPS2(); }