diff --git a/capi/src/io.rs b/capi/src/io.rs index 3a3e242b..ecf1b705 100644 --- a/capi/src/io.rs +++ b/capi/src/io.rs @@ -475,7 +475,7 @@ pub unsafe extern "C" fn chewing_config_set_int( ctx.editor .set_conversion_engine(Box::new(FuzzyChewingEngine::new())); options.lookup_strategy = LookupStrategy::FuzzyPartialPrefix; - ConversionEngineKind::ChewingEngine + ConversionEngineKind::FuzzyChewingEngine } _ => return ERROR, } diff --git a/src/conversion/simple.rs b/src/conversion/simple.rs index 375c06d1..62bf00cc 100644 --- a/src/conversion/simple.rs +++ b/src/conversion/simple.rs @@ -21,7 +21,7 @@ impl SimpleEngine { for (i, sym) in comp.symbols().iter().enumerate() { if comp - .selections + .selections() .iter() .any(|selection| selection.intersect_range(i, i + 1)) { diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 2701415d..933e7329 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -1120,6 +1120,10 @@ impl EnteringSyllable { None => self.spin_ignore(), } } + fn start_selecting_simple_engine(&self, editor: &mut SharedState) -> Transition { + editor.syl.clear(); + Transition::ToState(Box::new(Selecting::new_phrase_for_simple_engine(editor))) + } } impl State for EnteringSyllable { @@ -1175,9 +1179,18 @@ impl State for EnteringSyllable { .is_some() { shared.com.insert(Symbol::from(shared.syl.read())); + shared.syl.clear(); + if shared.options.conversion_engine + == ConversionEngineKind::SimpleEngine + { + self.start_selecting_simple_engine(shared) + } else { + self.start_entering() + } + } else { + shared.syl.clear(); + self.start_entering() } - shared.syl.clear(); - self.start_entering() } _ => self.spin_bell(), } @@ -1211,6 +1224,23 @@ impl Selecting { sel: Selector::Phrase(sel), } } + fn new_phrase_for_simple_engine(editor: &mut SharedState) -> Self { + editor.com.push_cursor(); + // editor.com.clamp_cursor(); + + let mut sel = PhraseSelector::new( + false, + editor.options.lookup_strategy, + editor.com.to_composition(), + ); + sel.init_single_word(editor.cursor()); + + Selecting { + page_no: 0, + action: SelectingAction::Replace, + sel: Selector::Phrase(sel), + } + } fn new_symbol(editor: &mut SharedState) -> Self { Selecting { page_no: 0, diff --git a/src/editor/selection/phrase.rs b/src/editor/selection/phrase.rs index 6242e27e..9632ed9a 100644 --- a/src/editor/selection/phrase.rs +++ b/src/editor/selection/phrase.rs @@ -65,6 +65,12 @@ impl PhraseSelector { } } + pub(crate) fn init_single_word(&mut self, cursor: usize) { + self.orig = cursor; + self.end = min(cursor, self.com.len()); + self.begin = self.end - 1; + } + pub(crate) fn begin(&self) -> usize { self.begin } diff --git a/tests/genkeystroke.c b/tests/genkeystroke.c index fbcb6d81..b9d06e7c 100644 --- a/tests/genkeystroke.c +++ b/tests/genkeystroke.c @@ -145,10 +145,16 @@ void show_interval_buffer(int x, int y, ChewingContext *ctx) void showBopomofo(ChewingContext *ctx) { if (chewing_get_ChiEngMode(ctx)) { - if (chewing_config_get_int(ctx, "chewing.fuzzy_search_mode")) { - addstr("[糊]"); - } else { - addstr("[中]"); + switch (chewing_config_get_int(ctx, "chewing.conversion_engine")) { + case 0: + addstr("[ㄅ]"); + break; + case 1: + addstr("[中]"); + break; + case 2: + addstr("[糊]"); + break; } } else { addstr("[英]"); @@ -283,6 +289,7 @@ int main(int argc, char *argv[]) int ch; int add_phrase_length; int kbtype; + int conversion_engine; if (argc < 2) { fprintf(stderr, "usage: genkeystroke filename\n"); @@ -352,11 +359,10 @@ int main(int argc, char *argv[]) mvaddstr(9, 20, "Ctrl + b : toggle Eng/Chi mode"); mvaddstr(10, 0, "F1, F2, F3, ..., F9 : Add user defined phrase"); mvaddstr(11, 0, "Ctrl + h : toggle Full/Half shape mode"); - mvaddstr(12, 0, "Ctrl + f : toggle Fuzzy Search mode"); - mvaddstr(13, 0, "Ctrl + s : toggle Simple mode"); - mvaddstr(14, 0, "Ctrl + n/p : Next / Previous keyboard layout"); + mvaddstr(12, 0, "Ctrl + s : cycle Simple/Chewing/Fuzzy mode"); + mvaddstr(13, 0, "Ctrl + n/p : Next / Previous keyboard layout"); show_commit_string(14, 0, ctx); - show_userphrase(7, 14, ctx); + show_userphrase(7, 15, ctx); show_edit_buffer(1, 0, ctx); ch = getch(); @@ -455,17 +461,11 @@ int main(int argc, char *argv[]) break; case KEY_CTRL_('D'): goto end; - case KEY_CTRL_('F'): - if (chewing_config_get_int(ctx, "chewing.fuzzy_search_mode") == TRUE) - chewing_config_set_int(ctx, "chewing.fuzzy_search_mode", FALSE); - else - chewing_config_set_int(ctx, "chewing.fuzzy_search_mode", TRUE); - break; case KEY_CTRL_('S'): - if (chewing_config_get_int(ctx, "chewing.conversion_engine") == 1) - chewing_config_set_int(ctx, "chewing.conversion_engine", 0); - else - chewing_config_set_int(ctx, "chewing.conversion_engine", 1); + conversion_engine = chewing_config_get_int(ctx, "chewing.conversion_engine"); + conversion_engine += 1; + conversion_engine %= 3; + chewing_config_set_int(ctx, "chewing.conversion_engine", conversion_engine); break; case KEY_CTRL_('H'): /* emulate Shift+Space */ chewing_handle_ShiftSpace(ctx); diff --git a/tests/test-bopomofo.c b/tests/test-bopomofo.c index f1c0e130..1e02f55c 100644 --- a/tests/test-bopomofo.c +++ b/tests/test-bopomofo.c @@ -1396,8 +1396,10 @@ void test_FuzzySearchMode_Hanyu() void test_SimpleEngine() { const TestData SIMPLE_INPUT[] = { - {"ru0320 5j4up ai6g4!", "簡單住因模市!" }, - {"ru0320 5j44up 2ai6g42!", "簡單注音模式!" }, + {"ru03120 15j41up 1ai61g41!", "簡單住因模市!" }, + {"ru0320 5j4up ai6g4!", "簡單住因模市!" }, + {"ru03120 15j44up 2ai61g42!", "簡單注音模式!" }, + {"ru03120 15j44up 2ai61g42!20 1tjp61", "單純簡單注音模式!" }, }; size_t i; ChewingContext *ctx;