From 366de4652be049164448f11c300519281c9dd0e1 Mon Sep 17 00:00:00 2001 From: YOSHIOKA Takuma Date: Sun, 21 Jan 2018 02:16:15 +0900 Subject: [PATCH] Add `abort-to-latin` and `abort-to-latin-passthrough` command This change and PR #47 (`Escape` keymap) enables us to use "vi-cooperative" keymap. `abort-to-latin` does "`abort`, then change to latin input mode". If the state changes on abort or mode change, key event is consumed. `abort-to-latin-passthrough` does "`abort`, then change to latin input mode, and let key event pass-through when no input string is discarded". "vi-cooperative" keymap will be achived by config such as the code below: ```json { "include": [ "default" ], "define": { "keymap": { "Escape": "abort-to-latin-passthrough", } } } ``` `abort-to-latin-passthrough` does not consume the key event even if the state changed. So, when the user type "C-j Esc" under the config above, application will receive "Esc" key event, in contrast to `abort-to-latin` command. --- libskk/state.vala | 45 ++++++++++++++++++++++++++++++++++++--------- rules/README.rules | 2 ++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/libskk/state.vala b/libskk/state.vala index 0a72f2c5..acfc30d4 100644 --- a/libskk/state.vala +++ b/libskk/state.vala @@ -423,15 +423,34 @@ 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-passthrough") { + bool something_changed; + bool allow_passthrough; 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 (); } + allow_passthrough = !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 `should_passthrough` + something_changed = true; + } + // if nothing changed by "abort-to-latin-passthrough" command, + // let key event pass through + if (command == "abort-to-latin-passthrough" && + allow_passthrough) { + return false; + } + return something_changed; } else if (command == "commit" || command == "commit-unhandled") { bool retval; @@ -613,7 +632,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-passthrough") { state.reset (); return true; } @@ -660,7 +681,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-passthrough") { state.reset (); return true; } @@ -720,7 +743,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-passthrough") { state.reset (); return true; } @@ -1000,7 +1025,9 @@ namespace Skk { } return true; } - else if (command == "abort") { + else if (command == "abort" || + command == "abort-to-latin" || + command == "abort-to-latin-passthrough") { state.candidates.clear (); state.cancel_okuri (); state.handler_type = typeof (StartStateHandler); diff --git a/rules/README.rules b/rules/README.rules index 5fb273f6..ef054635 100644 --- a/rules/README.rules +++ b/rules/README.rules @@ -103,6 +103,8 @@ The current available commands are: abbrev abort +abort-to-latin +abort-to-latin-passthrough commit commit-unhandled complete