Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(key_binder): add when: predicting condition #751

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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