Skip to content

Commit

Permalink
feat(key_binder): add when: predicting condition (#751)
Browse files Browse the repository at this point in the history
the new condition `when: predicting` allows paging key binding to comma,
period keys to be disabled when the active menu has tag `prediction`.

it's used with the `predictor` component in the librime-predict plugin.
see updates in data/minimal/default.yaml for example configuration.
  • Loading branch information
lotem authored Oct 29, 2023
1 parent cde8c21 commit 3bc65c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions data/minimal/default.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Rime default settings
# vim: set sw=2 sts=2 et:
# encoding: utf-8

config_version: "0.15.minimal"
config_version: "0.16.minimal"

schema_list:
- schema: luna_pinyin
Expand Down Expand Up @@ -118,6 +117,8 @@ key_binder:
- { when: has_menu, accept: equal, send: Page_Down }
- { when: paging, accept: comma, send: Page_Up }
- { when: has_menu, accept: period, send: Page_Down }
- { when: predicting, accept: comma, send: comma }
- { when: predicting, accept: period, send: period }
# hotkey switch
- { when: always, accept: Control+Shift+1, select: .next }
- { when: always, accept: Control+Shift+2, toggle: ascii_mode }
Expand Down
20 changes: 14 additions & 6 deletions src/rime/gear/key_binder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ namespace rime {

enum KeyBindingCondition {
kNever,
kWhenPaging, // user has changed page
kWhenHasMenu, // at least one candidate
kWhenComposing, // input string is not empty
kWhenPredicting, // showing prediction candidates
kWhenPaging, // user has changed page
kWhenHasMenu, // at least one candidate
kWhenComposing, // input string is not empty
kAlways,
};

static struct KeyBindingConditionDef {
KeyBindingCondition condition;
const char* name;
} condition_definitions[] = {{kWhenPaging, "paging"},
} condition_definitions[] = {{kWhenPredicting, "predicting"},
{kWhenPaging, "paging"},
{kWhenHasMenu, "has_menu"},
{kWhenComposing, "composing"},
{kAlways, "always"},
Expand Down Expand Up @@ -242,8 +244,14 @@ KeyBindingConditions::KeyBindingConditions(Context* ctx) {
}

Composition& comp = ctx->composition();
if (!comp.empty() && comp.back().HasTag("paging")) {
insert(kWhenPaging);
if (!comp.empty()) {
const Segment& last_seg = comp.back();
if (last_seg.HasTag("paging")) {
insert(kWhenPaging);
}
if (last_seg.HasTag("prediction")) {
insert(kWhenPredicting);
}
}
}

Expand Down

0 comments on commit 3bc65c9

Please sign in to comment.