From 4b782a0b03abe5274a39edc03a5157e632b541bf Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Sun, 14 Jul 2024 22:33:24 +0900 Subject: [PATCH] feat(editor): Add an option to disable fullwidth toggle key --- capi/src/io.rs | 8 +++++++- src/editor/mod.rs | 4 +++- tests/test-bopomofo.c | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/test-config.c | 1 + 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/capi/src/io.rs b/capi/src/io.rs index 43f1a35f..699a6bdc 100644 --- a/capi/src/io.rs +++ b/capi/src/io.rs @@ -304,7 +304,8 @@ pub unsafe extern "C" fn chewing_config_has_option( | "chewing.character_form" | "chewing.space_is_select_key" | "chewing.fuzzy_search_mode" - | "chewing.conversion_engine" => true, + | "chewing.conversion_engine" + | "chewing.enable_fullwidth_toggle_key" => true, _ => false, }; @@ -351,6 +352,7 @@ pub unsafe extern "C" fn chewing_config_get_int( ConversionEngineKind::ChewingEngine => 0, ConversionEngineKind::SimpleEngine => 1, }, + "chewing.enable_fullwidth_toggle_key" => option.enable_fullwidth_toggle_key as c_int, _ => ERROR, } } @@ -458,6 +460,10 @@ pub unsafe extern "C" fn chewing_config_set_int( _ => return ERROR, } } + "chewing.enable_fullwidth_toggle_key" => { + ensure_bool!(value); + options.enable_fullwidth_toggle_key = value > 0; + } _ => return ERROR, }; diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 072555b1..b252ae01 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -77,6 +77,7 @@ pub struct EditorOptions { pub user_phrase_add_dir: UserPhraseAddDirection, pub fuzzy_search: bool, pub conversion_engine: ConversionEngineKind, + pub enable_fullwidth_toggle_key: bool, } impl Default for EditorOptions { @@ -96,6 +97,7 @@ impl Default for EditorOptions { fuzzy_search: false, // FIXME may be out of sync with the engine used conversion_engine: ConversionEngineKind::ChewingEngine, + enable_fullwidth_toggle_key: true, } } } @@ -947,7 +949,7 @@ impl State for Entering { self.spin_absorb() } Up => self.spin_ignore(), - Space if ev.modifiers.shift => { + Space if ev.modifiers.shift && shared.options.enable_fullwidth_toggle_key => { shared.options.character_form = match shared.options.character_form { CharacterForm::Halfwidth => CharacterForm::Fullwidth, CharacterForm::Fullwidth => CharacterForm::Halfwidth, diff --git a/tests/test-bopomofo.c b/tests/test-bopomofo.c index 26e05bd4..cd4ed216 100644 --- a/tests/test-bopomofo.c +++ b/tests/test-bopomofo.c @@ -1120,6 +1120,48 @@ void test_ShiftSpace() chewing_delete(ctx); } +void test_ShiftSpaceDisabled() +{ + ChewingContext *ctx; + int mode; + + ctx = chewing_new(); + start_testcase(ctx, fd); + + chewing_config_set_int(ctx, "chewing.enable_fullwidth_toggle_key", 0); + + mode = chewing_get_ShapeMode(ctx); + ok(mode == HALFSHAPE_MODE, "mode shall be HALFSHAPE_MODE"); + + type_keystroke_by_string(ctx, ""); + mode = chewing_get_ShapeMode(ctx); + ok(mode == HALFSHAPE_MODE, "mode shall be HALFSHAPE_MODE"); + + type_keystroke_by_string(ctx, " "); + ok_commit_buffer(ctx, " "); /* Space */ + + chewing_set_ChiEngMode(ctx, SYMBOL_MODE); + type_keystroke_by_string(ctx, "a"); + ok_commit_buffer(ctx, "a"); /* a */ + + chewing_set_ChiEngMode(ctx, CHINESE_MODE); + type_keystroke_by_string(ctx, ""); + mode = chewing_get_ShapeMode(ctx); + ok(mode == HALFSHAPE_MODE, "mode shall be HALFSHAPE_MODE"); + + type_keystroke_by_string(ctx, " "); + ok_commit_buffer(ctx, " "); + + type_keystroke_by_string(ctx, "hk4 "); + ok_commit_buffer(ctx, "冊 "); + + chewing_set_ChiEngMode(ctx, SYMBOL_MODE); + type_keystroke_by_string(ctx, "a "); + ok_commit_buffer(ctx, " "); + + chewing_delete(ctx); +} + void test_Numlock_numeric_input() { const TestData NUMLOCK_INPUT[] = { @@ -2384,6 +2426,7 @@ int main(int argc, char *argv[]) test_PageUp(); test_PageDown(); test_ShiftSpace(); + test_ShiftSpaceDisabled(); test_Numlock(); test_Space(); test_FuzzySearchMode(); diff --git a/tests/test-config.c b/tests/test-config.c index 1f3c3041..19646a46 100644 --- a/tests/test-config.c +++ b/tests/test-config.c @@ -56,6 +56,7 @@ void test_has_option() ,"chewing.space_is_select_key" ,"chewing.fuzzy_search_mode" ,"chewing.conversion_engine" + ,"chewing.enable_fullwidth_toggle_key" }; ctx = chewing_new();