Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add abort-to-latin and abort-to-latin-unhandled command #48

Merged
merged 3 commits into from Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 37 additions & 9 deletions libskk/state.vala
Expand Up @@ -423,15 +423,35 @@ namespace Skk {
{
var command = state.lookup_key (key);
// check abort and commit event
if (command == "abort") {
bool retval;
if (command == "abort" ||
command == "abort-to-latin" ||
command == "abort-to-latin-unhandled") {
bool something_changed;
bool event_handled;
if (state.rom_kana_converter.preedit.length > 0) {
retval = true;
something_changed = true;
} else {
retval = state.recursive_edit_abort ();
something_changed = state.recursive_edit_abort ();
}
event_handled = something_changed;
state.reset ();
return retval;
if (command == "abort") {
return something_changed;
}
// change to latin mode
if (state.input_mode != InputMode.LATIN) {
state.input_mode = InputMode.LATIN;
// this change doesn't affect `event_handled`
something_changed = true;
}
// if the key event will not be handled by
// "abort-to-latin-unhandled" command,
// let key event pass through
if (command == "abort-to-latin-unhandled" &&
!event_handled) {
return false;
}
return something_changed;
} else if (command == "commit" ||
command == "commit-unhandled") {
bool retval;
Expand Down Expand Up @@ -613,7 +633,9 @@ namespace Skk {
ref KeyEvent key)
{
var command = state.lookup_key (key);
if (command == "abort") {
if (command == "abort" ||
command == "abort-to-latin" ||
command == "abort-to-latin-unhandled") {
state.reset ();
return true;
}
Expand Down Expand Up @@ -660,7 +682,9 @@ namespace Skk {
ref KeyEvent key)
{
var command = state.lookup_key (key);
if (command == "abort") {
if (command == "abort" ||
command == "abort-to-latin" ||
command == "abort-to-latin-unhandled") {
state.reset ();
return true;
}
Expand Down Expand Up @@ -720,7 +744,9 @@ namespace Skk {
ref KeyEvent key)
{
var command = state.lookup_key (key);
if (command == "abort") {
if (command == "abort" ||
command == "abort-to-latin" ||
command == "abort-to-latin-unhandled") {
state.reset ();
return true;
}
Expand Down Expand Up @@ -1000,7 +1026,9 @@ namespace Skk {
}
return true;
}
else if (command == "abort") {
else if (command == "abort" ||
command == "abort-to-latin" ||
command == "abort-to-latin-unhandled") {
state.candidates.clear ();
state.cancel_okuri ();
state.handler_type = typeof (StartStateHandler);
Expand Down
2 changes: 2 additions & 0 deletions rules/README.rules
Expand Up @@ -103,6 +103,8 @@ The current available commands are:

abbrev
abort
abort-to-latin
abort-to-latin-unhandled
commit
commit-unhandled
complete
Expand Down
47 changes: 47 additions & 0 deletions tests/basic.c
Expand Up @@ -449,6 +449,52 @@ inherit_typing_rule_for_dict_edit (void) {
destroy_context (context);
}

static void
abort_to_latin_commands (void) {
SkkContext *context;
GError *error;
SkkRule *rule;
SkkTransition transitions[] = {
// abort-to-latin: Test cases with no discarded inputs.
// In these cases, input mode should be changed to latin mode.
{ SKK_INPUT_MODE_HIRAGANA, "C-l", "", "", SKK_INPUT_MODE_LATIN },
{ SKK_INPUT_MODE_HIRAGANA, "a C-l", "", "あ", SKK_INPUT_MODE_LATIN },
// abort-to-latin: Test cases with discarded inputs.
// In these cases, the behaviour of `abort-to-latin` should be same as `abort`.
{ SKK_INPUT_MODE_HIRAGANA, "A C-l", "", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P C-l", "", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p C-l", "", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p o", "▽ぽぽ", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p o SPC C-l", "▽ぽぽ", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p o C-l", "", "", SKK_INPUT_MODE_HIRAGANA },
// abort-to-latin-unhandled: Test cases with no discarded inputs.
// In these cases, input mode should be changed to latin mode.
// Note: While these tests cannot represent, the key event will be
// propageted because it is "unhandled" by libskk.
// This enables "vi-cooperative" Escape key behaviour for example.
{ SKK_INPUT_MODE_HIRAGANA, "Q", "", "", SKK_INPUT_MODE_LATIN },
{ SKK_INPUT_MODE_HIRAGANA, "a Q", "", "あ", SKK_INPUT_MODE_LATIN },
// abort-to-latin-unhandled: Test cases with discarded inputs.
// These should be exactly the same behaviour as `abort-to-latin`.
{ SKK_INPUT_MODE_HIRAGANA, "A Q", "", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P Q", "", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p Q", "", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p o", "▽ぽぽ", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p o SPC Q", "▽ぽぽ", "", SKK_INPUT_MODE_HIRAGANA },
{ SKK_INPUT_MODE_HIRAGANA, "P o p o Q", "", "", SKK_INPUT_MODE_HIRAGANA },
{ 0, NULL }
};

context = create_context (TRUE, TRUE);
error = NULL;
rule = skk_rule_new ("test-aborts", &error);
g_assert_no_error (error);
skk_context_set_typing_rule (context, rule);
g_object_unref (rule);
check_transitions (context, transitions);
destroy_context (context);
}

int
main (int argc, char **argv) {
skk_init ();
Expand Down Expand Up @@ -496,5 +542,6 @@ main (int argc, char **argv) {
g_test_add_func ("/libskk/surrounding", surrounding);
g_test_add_func ("/libskk/start_preedit_no_delete", start_preedit_no_delete);
g_test_add_func ("/libskk/inherit_typing_rule_for_dict_edit", inherit_typing_rule_for_dict_edit);
g_test_add_func ("/libskk/abort_to_latin_commands", abort_to_latin_commands);
return g_test_run ();
}
11 changes: 11 additions & 0 deletions tests/rules/test-aborts/keymap/hiragana.json
@@ -0,0 +1,11 @@
{
"include": [
"default/hiragana"
],
"define": {
"keymap": {
"C-l": "abort-to-latin",
"Q": "abort-to-latin-unhandled"
}
}
}
4 changes: 4 additions & 0 deletions tests/rules/test-aborts/metadata.json
@@ -0,0 +1,4 @@
{
"name": "abort-to-latin* test rule",
"description": "Test case for abort-to-latin and abort-to-latin-unhandled"
}
3 changes: 3 additions & 0 deletions tests/rules/test-aborts/rom-kana/default.json
@@ -0,0 +1,3 @@
{
"include": ["default/default"]
}