From 3bc65c990546aa2062ecd1eb593d54d2949644cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E6=88=8E=E6=B0=8F?= Date: Mon, 30 Oct 2023 03:59:35 +0800 Subject: [PATCH] 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. --- data/minimal/default.yaml | 5 +++-- src/rime/gear/key_binder.cc | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/data/minimal/default.yaml b/data/minimal/default.yaml index d10c253b5..186665c29 100644 --- a/data/minimal/default.yaml +++ b/data/minimal/default.yaml @@ -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 @@ -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 } diff --git a/src/rime/gear/key_binder.cc b/src/rime/gear/key_binder.cc index 818e85cde..0d8e2f1a6 100644 --- a/src/rime/gear/key_binder.cc +++ b/src/rime/gear/key_binder.cc @@ -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"}, @@ -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); + } } }