Skip to content

Commit 3b5dbf6

Browse files
SleepyBaglotem
authored andcommitted
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
}

0 commit comments

Comments
 (0)