Skip to content

Commit 3bc65c9

Browse files
authored
feat(key_binder): add when: predicting condition (#751)
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.
1 parent cde8c21 commit 3bc65c9

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

data/minimal/default.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Rime default settings
2-
# vim: set sw=2 sts=2 et:
32
# encoding: utf-8
43

5-
config_version: "0.15.minimal"
4+
config_version: "0.16.minimal"
65

76
schema_list:
87
- schema: luna_pinyin
@@ -118,6 +117,8 @@ key_binder:
118117
- { when: has_menu, accept: equal, send: Page_Down }
119118
- { when: paging, accept: comma, send: Page_Up }
120119
- { when: has_menu, accept: period, send: Page_Down }
120+
- { when: predicting, accept: comma, send: comma }
121+
- { when: predicting, accept: period, send: period }
121122
# hotkey switch
122123
- { when: always, accept: Control+Shift+1, select: .next }
123124
- { when: always, accept: Control+Shift+2, toggle: ascii_mode }

src/rime/gear/key_binder.cc

+14-6
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ namespace rime {
2222

2323
enum KeyBindingCondition {
2424
kNever,
25-
kWhenPaging, // user has changed page
26-
kWhenHasMenu, // at least one candidate
27-
kWhenComposing, // input string is not empty
25+
kWhenPredicting, // showing prediction candidates
26+
kWhenPaging, // user has changed page
27+
kWhenHasMenu, // at least one candidate
28+
kWhenComposing, // input string is not empty
2829
kAlways,
2930
};
3031

3132
static struct KeyBindingConditionDef {
3233
KeyBindingCondition condition;
3334
const char* name;
34-
} condition_definitions[] = {{kWhenPaging, "paging"},
35+
} condition_definitions[] = {{kWhenPredicting, "predicting"},
36+
{kWhenPaging, "paging"},
3537
{kWhenHasMenu, "has_menu"},
3638
{kWhenComposing, "composing"},
3739
{kAlways, "always"},
@@ -242,8 +244,14 @@ KeyBindingConditions::KeyBindingConditions(Context* ctx) {
242244
}
243245

244246
Composition& comp = ctx->composition();
245-
if (!comp.empty() && comp.back().HasTag("paging")) {
246-
insert(kWhenPaging);
247+
if (!comp.empty()) {
248+
const Segment& last_seg = comp.back();
249+
if (last_seg.HasTag("paging")) {
250+
insert(kWhenPaging);
251+
}
252+
if (last_seg.HasTag("prediction")) {
253+
insert(kWhenPredicting);
254+
}
247255
}
248256
}
249257

0 commit comments

Comments
 (0)