Skip to content

Commit c91077d

Browse files
authored
allow using keypad to select candidate in scroll mode (#275)
1 parent 2bc5a3d commit c91077d

File tree

3 files changed

+97
-61
lines changed

3 files changed

+97
-61
lines changed

assets/po/zh_CN.po

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ msgstr "闪烁"
111111
msgid "Static"
112112
msgstr "静止"
113113

114-
#: webpanel/webpanel.h:30 webpanel/webpanel.h:34 webpanel/webpanel.h:289
114+
#: webpanel/webpanel.h:30 webpanel/webpanel.h:34 webpanel/webpanel.h:290
115115
msgid "Text"
116116
msgstr "文本"
117117

@@ -291,210 +291,218 @@ msgstr "下一页"
291291
msgid "Commit"
292292
msgstr "提交"
293293

294-
#: webpanel/webpanel.h:228
294+
#: webpanel/webpanel.h:226
295295
msgid "Select candidate"
296296
msgstr "选词"
297297

298-
#: webpanel/webpanel.h:233
298+
#: webpanel/webpanel.h:229
299+
msgid "Use main keyboard number keys to select candidate"
300+
msgstr "用主键盘数字键选词"
301+
302+
#: webpanel/webpanel.h:232
303+
msgid "Use keypad number keys to select candidate"
304+
msgstr "用小键盘数字键选词"
305+
306+
#: webpanel/webpanel.h:234
299307
msgid "Optimize for Hyper key"
300308
msgstr "针对 Hyper 键优化"
301309

302-
#: webpanel/webpanel.h:239
310+
#: webpanel/webpanel.h:240
303311
msgid "Layout"
304312
msgstr "布局"
305313

306-
#: webpanel/webpanel.h:243
314+
#: webpanel/webpanel.h:244
307315
msgid "Writing mode"
308316
msgstr "书写模式"
309317

310-
#: webpanel/webpanel.h:246
318+
#: webpanel/webpanel.h:247
311319
msgid "Typography awareness for IM"
312320
msgstr "输入法感知版式"
313321

314-
#: webpanel/webpanel.h:250
322+
#: webpanel/webpanel.h:251
315323
msgid "Paging buttons style"
316324
msgstr "翻页按钮样式"
317325

318-
#: webpanel/webpanel.h:255
326+
#: webpanel/webpanel.h:256
319327
msgid "Image"
320328
msgstr "图片"
321329

322-
#: webpanel/webpanel.h:256
330+
#: webpanel/webpanel.h:257
323331
msgid "Blur"
324332
msgstr "模糊"
325333

326-
#: webpanel/webpanel.h:257
334+
#: webpanel/webpanel.h:258
327335
msgid "Shadow"
328336
msgstr "阴影"
329337

330-
#: webpanel/webpanel.h:265
338+
#: webpanel/webpanel.h:266
331339
msgid "Text font family"
332340
msgstr "文本字体族"
333341

334-
#: webpanel/webpanel.h:267
342+
#: webpanel/webpanel.h:268
335343
msgid "Text font size"
336344
msgstr "文本字号"
337345

338-
#: webpanel/webpanel.h:269
346+
#: webpanel/webpanel.h:270
339347
msgid "Label font family"
340348
msgstr "标签字体族"
341349

342-
#: webpanel/webpanel.h:271
350+
#: webpanel/webpanel.h:272
343351
msgid "Label font size"
344352
msgstr "标签字号"
345353

346-
#: webpanel/webpanel.h:273
354+
#: webpanel/webpanel.h:274
347355
msgid "Comment font family"
348356
msgstr "注释字体族"
349357

350-
#: webpanel/webpanel.h:275
358+
#: webpanel/webpanel.h:276
351359
msgid "Comment font size"
352360
msgstr "注释字号"
353361

354-
#: webpanel/webpanel.h:278
362+
#: webpanel/webpanel.h:279
355363
msgid "Preedit font family"
356364
msgstr "预编辑字体族"
357365

358-
#: webpanel/webpanel.h:280
366+
#: webpanel/webpanel.h:281
359367
msgid "Preedit font size"
360368
msgstr "预编辑字号"
361369

362-
#: webpanel/webpanel.h:282
370+
#: webpanel/webpanel.h:283
363371
msgid "User font dir"
364372
msgstr "用户字体目录"
365373

366-
#: webpanel/webpanel.h:283
374+
#: webpanel/webpanel.h:284
367375
msgid "System font dir"
368376
msgstr "系统字体目录"
369377

370-
#: webpanel/webpanel.h:288
378+
#: webpanel/webpanel.h:289
371379
msgid "Style"
372380
msgstr "样式"
373381

374-
#: webpanel/webpanel.h:294
382+
#: webpanel/webpanel.h:295
375383
msgid "Mark style"
376384
msgstr "标记样式"
377385

378-
#: webpanel/webpanel.h:295
386+
#: webpanel/webpanel.h:296
379387
msgid "Mark text"
380388
msgstr "标记文本"
381389

382-
#: webpanel/webpanel.h:297
390+
#: webpanel/webpanel.h:298
383391
msgid "Hover behavior"
384392
msgstr "悬停行为"
385393

386-
#: webpanel/webpanel.h:303
394+
#: webpanel/webpanel.h:304
387395
msgid "Border width (px)"
388396
msgstr "边框宽度(px)"
389397

390-
#: webpanel/webpanel.h:306
398+
#: webpanel/webpanel.h:307
391399
msgid "Border radius (px)"
392400
msgstr "边框半径(px)"
393401

394-
#: webpanel/webpanel.h:307
402+
#: webpanel/webpanel.h:308
395403
msgid "Margin (px)"
396404
msgstr "外边距(px)"
397405

398-
#: webpanel/webpanel.h:310
406+
#: webpanel/webpanel.h:311
399407
msgid "Highlight radius (px)"
400408
msgstr "高亮半径(px)"
401409

402-
#: webpanel/webpanel.h:313
410+
#: webpanel/webpanel.h:314
403411
msgid "Top padding (px)"
404412
msgstr "顶填充(px)"
405413

406-
#: webpanel/webpanel.h:315
414+
#: webpanel/webpanel.h:316
407415
msgid "Right padding (px)"
408416
msgstr "右填充(px)"
409417

410-
#: webpanel/webpanel.h:317
418+
#: webpanel/webpanel.h:318
411419
msgid "Bottom padding (px)"
412420
msgstr "底填充(px)"
413421

414-
#: webpanel/webpanel.h:320
422+
#: webpanel/webpanel.h:321
415423
msgid "Left padding (px)"
416424
msgstr "左填充(px)"
417425

418-
#: webpanel/webpanel.h:322
426+
#: webpanel/webpanel.h:323
419427
msgid "Gap between label, text and comment (px)"
420428
msgstr "标签、文本、注释间隔(px)"
421429

422-
#: webpanel/webpanel.h:325
430+
#: webpanel/webpanel.h:326
423431
msgid "Vertical minimum width (px)"
424432
msgstr "垂直时最小宽度(px)"
425433

426-
#: webpanel/webpanel.h:328
434+
#: webpanel/webpanel.h:329
427435
msgid "Scroll cell width (px)"
428436
msgstr "卷轴单元格宽度 (px)"
429437

430-
#: webpanel/webpanel.h:331
438+
#: webpanel/webpanel.h:332
431439
msgid "Horizontal divider width (px)"
432440
msgstr "水平分隔线宽度(px)"
433441

434-
#: webpanel/webpanel.h:340
442+
#: webpanel/webpanel.h:341
435443
msgid "User CSS"
436444
msgstr "用户 CSS"
437445

438-
#: webpanel/webpanel.h:341
446+
#: webpanel/webpanel.h:342
439447
msgid "Copy HTML"
440448
msgstr "复制 HTML"
441449

442-
#: webpanel/webpanel.h:342
450+
#: webpanel/webpanel.h:343
443451
msgid "Plugin dir"
444452
msgstr "插件目录"
445453

446-
#: webpanel/webpanel.h:344
454+
#: webpanel/webpanel.h:345
447455
msgid "I know there may be risks for using plugins"
448456
msgstr "我知道使用插件可能有风险"
449457

450-
#: webpanel/webpanel.h:347
458+
#: webpanel/webpanel.h:348
451459
msgid "Plugins"
452460
msgstr "插件"
453461

454-
#: webpanel/webpanel.h:349
462+
#: webpanel/webpanel.h:350
455463
msgid "Dangerous API for JavaScript plugins"
456464
msgstr "用于 JavaScript 插件的危险 API"
457465

458-
#: webpanel/webpanel.h:352
466+
#: webpanel/webpanel.h:353
459467
msgid "Basic"
460468
msgstr "基础"
461469

462-
#: webpanel/webpanel.h:353
470+
#: webpanel/webpanel.h:354
463471
msgid "Light mode"
464472
msgstr "浅色模式"
465473

466-
#: webpanel/webpanel.h:354
474+
#: webpanel/webpanel.h:355
467475
msgid "Dark mode"
468476
msgstr "深色模式"
469477

470-
#: webpanel/webpanel.h:355
478+
#: webpanel/webpanel.h:356
471479
msgid "Typography"
472480
msgstr "版式"
473481

474-
#: webpanel/webpanel.h:356
482+
#: webpanel/webpanel.h:357
475483
msgid "Scroll mode"
476484
msgstr "卷轴模式"
477485

478-
#: webpanel/webpanel.h:357
486+
#: webpanel/webpanel.h:358
479487
msgid "Background"
480488
msgstr "背景"
481489

482-
#: webpanel/webpanel.h:358
490+
#: webpanel/webpanel.h:359
483491
msgid "Font"
484492
msgstr "字体"
485493

486-
#: webpanel/webpanel.h:359
494+
#: webpanel/webpanel.h:360
487495
msgid "Caret"
488496
msgstr "光标"
489497

490-
#: webpanel/webpanel.h:360
498+
#: webpanel/webpanel.h:361
491499
msgid "Highlight"
492500
msgstr "高亮"
493501

494-
#: webpanel/webpanel.h:361
502+
#: webpanel/webpanel.h:362
495503
msgid "Size"
496504
msgstr "尺寸"
497505

498-
#: webpanel/webpanel.h:362
506+
#: webpanel/webpanel.h:363
499507
msgid "Advanced"
500508
msgstr "高级"

webpanel/webpanel.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,40 @@ WebPanel::WebPanel(Instance *instance)
176176
candidate_window::scroll_key_action_t::nine,
177177
candidate_window::scroll_key_action_t::zero,
178178
};
179+
static const KeyList mainKeyboardNumberKeys = {
180+
Key(FcitxKey_1), Key(FcitxKey_2), Key(FcitxKey_3),
181+
Key(FcitxKey_4), Key(FcitxKey_5), Key(FcitxKey_6),
182+
Key(FcitxKey_7), Key(FcitxKey_8), Key(FcitxKey_9),
183+
Key(FcitxKey_0)};
184+
static const KeyList keypadNumberKeys = {
185+
Key(FcitxKey_KP_1), Key(FcitxKey_KP_2), Key(FcitxKey_KP_3),
186+
Key(FcitxKey_KP_4), Key(FcitxKey_KP_5), Key(FcitxKey_KP_6),
187+
Key(FcitxKey_KP_7), Key(FcitxKey_KP_8), Key(FcitxKey_KP_9),
188+
Key(FcitxKey_KP_0)};
189+
int keyIndex = -1;
179190
if (int i =
180191
key.keyListIndex(*config_.scrollMode->selectCandidate);
181-
i >= 0 && i < selectActions.size()) {
192+
i >= 0 && i < 10) {
193+
keyIndex = i;
194+
}
195+
if (keyIndex < 0 &&
196+
*config_.scrollMode->useMainKeyboardNumberKeys) {
197+
int i = key.keyListIndex(mainKeyboardNumberKeys);
198+
if (i >= 0 && i < 10) {
199+
keyIndex = i;
200+
}
201+
}
202+
if (keyIndex < 0 && *config_.scrollMode->useKeypadNumberKeys) {
203+
int i = key.keyListIndex(keypadNumberKeys);
204+
if (i >= 0 && i < 10) {
205+
keyIndex = i;
206+
}
207+
}
208+
if (keyIndex >= 0) {
182209
if (keyEvent.isRelease()) {
183210
return;
184211
}
185-
window_->scroll_key_action(selectActions[i]);
212+
window_->scroll_key_action(selectActions[keyIndex]);
186213
return keyEvent.filterAndAccept();
187214
}
188215
const std::vector<std::pair<

webpanel/webpanel.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,13 @@ FCITX_CONFIGURATION(
223223
this, "PageDown", _("Page down"), {Key(FcitxKey_Page_Down)}};
224224
Option<KeyList> commit{this, "Commit", _("Commit"), {Key(FcitxKey_space)}};
225225
Option<KeyList> selectCandidate{
226-
this,
227-
"SelectCandidate",
228-
_("Select candidate"),
229-
{Key(FcitxKey_1), Key(FcitxKey_2), Key(FcitxKey_3), Key(FcitxKey_4),
230-
Key(FcitxKey_5), Key(FcitxKey_6), Key(FcitxKey_7), Key(FcitxKey_8),
231-
Key(FcitxKey_9), Key(FcitxKey_0)}};
226+
this, "SelectCandidate", _("Select candidate"), {}};
227+
Option<bool> useMainKeyboardNumberKeys{
228+
this, "UseMainKeyboardNumberKeys",
229+
_("Use main keyboard number keys to select candidate"), true};
230+
Option<bool> useKeypadNumberKeys{
231+
this, "UseKeypadNumberKeys",
232+
_("Use keypad number keys to select candidate"), false};
232233
Option<bool> optimizeForHyperKey{this, "OptimizeForHyperKey",
233234
_("Optimize for Hyper key"), true};);
234235

0 commit comments

Comments
 (0)