Skip to content

Commit 94cf479

Browse files
committed
feat(chord_composer): support chording with Shift keys
1 parent 7c08a90 commit 94cf479

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/rime/gear/chord_composer.cc

+23-3
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,39 @@ ProcessResult ChordComposer::ProcessFunctionKey(const KeyEvent& key_event) {
6464
return kNoop;
6565
}
6666

67+
// Note: QWERTY layout only.
68+
static const char map_to_base_layer[] = {
69+
" 1'3457'908=,-./"
70+
"0123456789;;,=./"
71+
"2abcdefghijklmno"
72+
"pqrstuvwxyz[\\]6-"
73+
"`abcdefghijklmno"
74+
"pqrstuvwxyz[\\]`"
75+
};
76+
77+
inline static int get_base_layer_key_code(const KeyEvent& key_event) {
78+
int ch = key_event.keycode();
79+
bool is_shift = key_event.shift();
80+
return (is_shift && ch >= 0x20 && ch <= 0x7e)
81+
? map_to_base_layer[ch - 0x20] : ch;
82+
}
83+
6784
ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
6885
bool chording = !chord_.empty();
69-
if (key_event.shift() || key_event.ctrl() || key_event.alt()) {
86+
if (key_event.ctrl() || key_event.alt()) {
7087
raw_sequence_.clear();
7188
ClearChord();
7289
return chording ? kAccepted : kNoop;
7390
}
74-
bool is_key_up = key_event.release();
75-
int ch = key_event.keycode();
91+
int ch = get_base_layer_key_code(key_event);
7692
// non chording key
7793
if (std::find(chording_keys_.begin(),
7894
chording_keys_.end(),
7995
KeyEvent{ch, 0}) == chording_keys_.end()) {
8096
return chording ? kAccepted : kNoop;
8197
}
8298
// chording key
99+
bool is_key_up = key_event.release();
83100
if (is_key_up) {
84101
if (pressed_.erase(ch) != 0 && pressed_.empty()) {
85102
FinishChord();
@@ -95,6 +112,9 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
95112
}
96113

97114
ProcessResult ChordComposer::ProcessKeyEvent(const KeyEvent& key_event) {
115+
if (engine_->context()->get_option("ascii_mode")) {
116+
return kNoop;
117+
}
98118
if (pass_thru_) {
99119
return ProcessFunctionKey(key_event);
100120
}

0 commit comments

Comments
 (0)