Skip to content

Commit

Permalink
Add abort-to-latin and abort-to-latin-passthrough command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
YOSHIOKA Takuma committed Jan 22, 2018
1 parent afe959b commit 366de46
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
45 changes: 36 additions & 9 deletions libskk/state.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions rules/README.rules
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ The current available commands are:

abbrev
abort
abort-to-latin
abort-to-latin-passthrough
commit
commit-unhandled
complete
Expand Down

0 comments on commit 366de46

Please sign in to comment.