Skip to content

Commit 3b5dbf6

Browse files
SleepyBaglotem
authored andcommittedSep 5, 2019
feat(key_binder): bind key to a key sequence
Closes #301 To bind a key to a key sequence, set 'send_sequence' attribute of a 'key_binder/bindings' entry. Special named keys should be around with "{" and "}". Notice that you have to add quotes when writing a filed with "{" or "}" in a yaml file. For example: key_binder: bindings: - { when: composing, accept: a, send_sequence: aa } - { when: composing, accept: Right, send_sequence: "{Right}{Right}" } - { when: composing, accept: Left, send_sequence: "aa{Left}{Left}" }
1 parent 75a60dc commit 3b5dbf6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed
 

‎src/rime/gear/key_binder.cc

+14-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static KeyBindingCondition translate_condition(const string& str) {
4848

4949
struct KeyBinding {
5050
KeyBindingCondition whence;
51-
KeyEvent target;
51+
KeySequence target;
5252
function<void (Engine* engine)> action;
5353

5454
bool operator< (const KeyBinding& o) const {
@@ -118,11 +118,20 @@ void KeyBindings::LoadBindings(const an<ConfigList>& bindings) {
118118
continue;
119119
}
120120
if (auto target = map->GetValue("send")) {
121-
if (!binding.target.Parse(target->str())) {
121+
KeyEvent key;
122+
if (key.Parse(target->str())) {
123+
binding.target.push_back(std::move(key));
124+
} else {
122125
LOG(WARNING) << "invalid key binding #" << i << ".";
123126
continue;
124127
}
125128
}
129+
else if (auto target = map->GetValue("send_sequence")) {
130+
if (!binding.target.Parse(target->str())) {
131+
LOG(WARNING) << "invalid key sequence #" << i << ".";
132+
continue;
133+
}
134+
}
126135
else if (auto option = map->GetValue("toggle")) {
127136
binding.action = std::bind(&toggle_option, _1, option->str());
128137
}
@@ -203,7 +212,9 @@ void KeyBinder::PerformKeyBinding(const KeyBinding& binding) {
203212
}
204213
else {
205214
redirecting_ = true;
206-
engine_->ProcessKey(binding.target);
215+
for (const KeyEvent& key_event : binding.target) {
216+
engine_->ProcessKey(key_event);
217+
}
207218
redirecting_ = false;
208219
}
209220
}

3 commit comments

Comments
 (3)

1yx commented on Mar 13, 2020

@1yx

Good Job! 我刚好试图在 rime 上找一种方案实现中英混排时加空格,正如 https://github.com/vinta/pangu.js 所做的。
{ when: composing, accept: Return, send_sequence: " {Escape} " }
似乎这样的配置就可以实现。

david50407 commented on May 18, 2020

@david50407

有計劃什麼時候會 release 這個 feature 嗎?

lotem commented on May 19, 2020

@lotem
Member

有計劃什麼時候會 release 這個 feature 嗎?

還沒有。不過最近 https://github.com/BYVoid/OpenCC 又開始更新了,且發佈了API的變更。librime 也不得不準備跟進。

Please sign in to comment.