Skip to content

Commit

Permalink
feat(editor): Add an option to disable fullwidth toggle key
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jul 14, 2024
1 parent 0ea5400 commit 4b782a0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
8 changes: 7 additions & 1 deletion capi/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,

Check warning on line 355 in capi/src/io.rs

View check run for this annotation

Codecov / codecov/patch

capi/src/io.rs#L355

Added line #L355 was not covered by tests
_ => ERROR,
}
}
Expand Down Expand Up @@ -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,
};

Expand Down
4 changes: 3 additions & 1 deletion src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -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,
Expand Down
43 changes: 43 additions & 0 deletions tests/test-bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<SS>");
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, "<SS>");
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 <E>");
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[] = {
Expand Down Expand Up @@ -2384,6 +2426,7 @@ int main(int argc, char *argv[])
test_PageUp();
test_PageDown();
test_ShiftSpace();
test_ShiftSpaceDisabled();
test_Numlock();
test_Space();
test_FuzzySearchMode();
Expand Down
1 change: 1 addition & 0 deletions tests/test-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4b782a0

Please sign in to comment.