Skip to content

Commit

Permalink
feat(key_binder): add when: predicting condition (rime#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 and graphemecluster committed Oct 29, 2023
1 parent e1d9a96 commit f2f6abe
Showing 1 changed file with 14 additions and 6 deletions.
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 f2f6abe

Please # to comment.