Skip to content

Commit

Permalink
feat(editor): Show notification about mode switches triggered by input
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Jul 15, 2024
1 parent dfe0e82 commit cbca96b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
34 changes: 19 additions & 15 deletions src/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,6 @@ impl Editor {
}
self.shared.options = options;
}
pub fn switch_character_form(&mut self) {
self.shared.options = EditorOptions {
character_form: match self.shared.options.character_form {
CharacterForm::Halfwidth => CharacterForm::Fullwidth,
CharacterForm::Fullwidth => CharacterForm::Halfwidth,
},
..self.shared.options
};
}

pub fn entering_syllable(&self) -> bool {
!self.shared.syl.is_empty()
}
Expand Down Expand Up @@ -647,6 +637,23 @@ impl SharedState {
},
..self.options
};
match self.options.language_mode {
LanguageMode::Chinese => self.notice_buffer = format!("切換為中文模式"),
LanguageMode::English => self.notice_buffer = format!("切換為英數模式"),
}
}
fn switch_character_form(&mut self) {
self.options = EditorOptions {
character_form: match self.options.character_form {
CharacterForm::Halfwidth => CharacterForm::Fullwidth,
CharacterForm::Fullwidth => CharacterForm::Halfwidth,
},
..self.options
};
match self.options.character_form {
CharacterForm::Halfwidth => self.notice_buffer = format!("切換為半形模式"),
CharacterForm::Fullwidth => self.notice_buffer = format!("切換為全形模式"),
}
}
fn cancel_selecting(&mut self) {
self.com.pop_cursor();
Expand Down Expand Up @@ -950,10 +957,7 @@ impl State for Entering {
}
Up => self.spin_ignore(),
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,
};
shared.switch_character_form();
self.spin_absorb()
}
Space
Expand Down Expand Up @@ -1709,7 +1713,7 @@ mod tests {
let sym_sel = SymbolSelector::default();
let mut editor = Editor::new(conversion_engine, dict, estimate, abbrev, sym_sel);

editor.switch_character_form();
editor.shared.switch_character_form();

let steps = [
(
Expand Down
8 changes: 3 additions & 5 deletions tests/genkeystroke.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,9 @@ int main(int argc, char *argv[])
else
chewing_config_set_int(ctx, "chewing.conversion_engine", 1);
break;
case KEY_CTRL_('H'): /* emulate Shift */
if (chewing_get_ShapeMode(ctx) == FULLSHAPE_MODE)
chewing_set_ShapeMode(ctx, HALFSHAPE_MODE);
else
chewing_set_ShapeMode(ctx, FULLSHAPE_MODE);
case KEY_CTRL_('H'): /* emulate Shift+Space */
chewing_handle_ShiftSpace(ctx);
fprintf(fout, "<SS>");
break;
case KEY_NPAGE:
chewing_handle_PageDown(ctx);
Expand Down
10 changes: 10 additions & 0 deletions tests/test-bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,18 @@ void test_Capslock()
mode = chewing_get_ChiEngMode(ctx);
ok(mode == SYMBOL_MODE, "mode shall change to SYMBOL_MODE");

ok_aux_buffer(ctx, "切換為英數模式");
ok_bopomofo_buffer(ctx, "");
ok_preedit_buffer(ctx, "");
ok_commit_buffer(ctx, "");

type_keystroke_by_string(ctx, "<CB>");

mode = chewing_get_ChiEngMode(ctx);
ok(mode == CHINESE_MODE, "mode shall change to CHINESE_MODE");

ok_aux_buffer(ctx, "切換為中文模式");

chewing_delete(ctx);
}

Expand Down Expand Up @@ -1094,6 +1102,7 @@ void test_ShiftSpace()
type_keystroke_by_string(ctx, "<SS>");
mode = chewing_get_ShapeMode(ctx);
ok(mode == FULLSHAPE_MODE, "mode shall be FULLSHAPE_MODE");
ok_aux_buffer(ctx, "切換為全形模式");

type_keystroke_by_string(ctx, " ");
ok_commit_buffer(ctx, "\xE3\x80\x80"); /* Fullshape Space (U+3000) */
Expand All @@ -1106,6 +1115,7 @@ void test_ShiftSpace()
type_keystroke_by_string(ctx, "<SS>");
mode = chewing_get_ShapeMode(ctx);
ok(mode == HALFSHAPE_MODE, "mode shall be HALFSHAPE_MODE");
ok_aux_buffer(ctx, "切換為半形模式");

type_keystroke_by_string(ctx, " ");
ok_commit_buffer(ctx, " ");
Expand Down

0 comments on commit cbca96b

Please sign in to comment.