Skip to content

Commit 997f153

Browse files
committed
feat(chord): Tab, BackSpace, Return can be used as chording keys
1 parent 764aea9 commit 997f153

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

SquirrelInputController.m

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ -(BOOL)processKey:(int)rime_keycode modifiers:(int)rime_modifiers
176176

177177
// Simulate key-ups for every interesting key-down for chord-typing.
178178
if (handled) {
179-
bool is_basic_latin =
180-
rime_keycode >= XK_space && rime_keycode <= XK_asciitilde && rime_modifiers == 0;
181-
if (is_basic_latin && rime_get_api()->get_option(_session, "_chord_typing")) {
179+
bool is_chording_key = rime_modifiers == 0 &&
180+
((rime_keycode >= XK_space && rime_keycode <= XK_asciitilde) ||
181+
rime_keycode == XK_Tab ||
182+
rime_keycode == XK_BackSpace ||
183+
rime_keycode == XK_Return);
184+
if (is_chording_key &&
185+
rime_get_api()->get_option(_session, "_chord_typing")) {
182186
[self updateChord:rime_keycode];
183187
}
184188
else {
@@ -189,20 +193,47 @@ -(BOOL)processKey:(int)rime_keycode modifiers:(int)rime_modifiers
189193
return handled;
190194
}
191195

196+
static char keycode_to_char(int keycode) {
197+
switch (keycode) {
198+
case XK_Tab:
199+
return '\t';
200+
case XK_BackSpace:
201+
return'\b';
202+
case XK_Return:
203+
return '\n';
204+
default:
205+
return (char)keycode;
206+
}
207+
}
208+
209+
static int char_to_keycode(char ch) {
210+
switch (ch) {
211+
case '\t':
212+
return XK_Tab;
213+
case '\b':
214+
return XK_BackSpace;
215+
case '\n':
216+
return XK_Return;
217+
default:
218+
return ch;
219+
}
220+
}
221+
192222
-(void)onChordTimer:(NSTimer *)timer
193223
{
194224
if (_chord[0] && _session) {
195225
// simulate key-ups
196226
for (char *p = _chord; *p; ++p) {
197-
rime_get_api()->process_key(_session, *p, kReleaseMask);
227+
rime_get_api()->process_key(_session, char_to_keycode(*p), kReleaseMask);
198228
}
199229
[self rimeUpdate];
200230
}
201231
[self clearChord];
202232
}
203233

204-
-(void)updateChord:(int)ch
234+
-(void)updateChord:(int)keycode
205235
{
236+
char ch = keycode_to_char(keycode);
206237
char *p = strchr(_chord, ch);
207238
if (p != NULL) {
208239
// just repeating

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy