Skip to content

Commit c032d14

Browse files
authored
configurable select candidate keys in scroll mode (#249)
1 parent 1d7bb11 commit c032d14

File tree

4 files changed

+77
-74
lines changed

4 files changed

+77
-74
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"clangd.arguments": [
33
"-background-index",
4-
"-compile-commands-dir=build"
4+
"-compile-commands-dir=build/arm64"
55
]
66
}

assets/po/zh_CN.po

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ msgstr "闪烁"
9595
msgid "Static"
9696
msgstr "静止"
9797

98-
#: webpanel/webpanel.h:30 webpanel/webpanel.h:34 webpanel/webpanel.h:267
98+
#: webpanel/webpanel.h:30 webpanel/webpanel.h:34 webpanel/webpanel.h:273
9999
msgid "Text"
100100
msgstr "文本"
101101

@@ -263,202 +263,206 @@ msgstr "下一页"
263263
msgid "Commit"
264264
msgstr "提交"
265265

266-
#: webpanel/webpanel.h:211
266+
#: webpanel/webpanel.h:212
267+
msgid "Select candidate"
268+
msgstr "选词"
269+
270+
#: webpanel/webpanel.h:217
267271
msgid "Optimize for Hyper key"
268272
msgstr "针对 Hyper 键优化"
269273

270-
#: webpanel/webpanel.h:217
274+
#: webpanel/webpanel.h:223
271275
msgid "Layout"
272276
msgstr "布局"
273277

274-
#: webpanel/webpanel.h:221
278+
#: webpanel/webpanel.h:227
275279
msgid "Writing mode"
276280
msgstr "书写模式"
277281

278-
#: webpanel/webpanel.h:224
282+
#: webpanel/webpanel.h:230
279283
msgid "Typography awareness for IM"
280284
msgstr "输入法感知版式"
281285

282-
#: webpanel/webpanel.h:228
286+
#: webpanel/webpanel.h:234
283287
msgid "Paging buttons style"
284288
msgstr "翻页按钮样式"
285289

286-
#: webpanel/webpanel.h:233
290+
#: webpanel/webpanel.h:239
287291
msgid "Image"
288292
msgstr "图片"
289293

290-
#: webpanel/webpanel.h:234
294+
#: webpanel/webpanel.h:240
291295
msgid "Blur"
292296
msgstr "模糊"
293297

294-
#: webpanel/webpanel.h:235
298+
#: webpanel/webpanel.h:241
295299
msgid "Shadow"
296300
msgstr "阴影"
297301

298-
#: webpanel/webpanel.h:243
302+
#: webpanel/webpanel.h:249
299303
msgid "Text font family"
300304
msgstr "文本字体族"
301305

302-
#: webpanel/webpanel.h:245
306+
#: webpanel/webpanel.h:251
303307
msgid "Text font size"
304308
msgstr "文本字号"
305309

306-
#: webpanel/webpanel.h:247
310+
#: webpanel/webpanel.h:253
307311
msgid "Label font family"
308312
msgstr "标签字体族"
309313

310-
#: webpanel/webpanel.h:249
314+
#: webpanel/webpanel.h:255
311315
msgid "Label font size"
312316
msgstr "标签字号"
313317

314-
#: webpanel/webpanel.h:251
318+
#: webpanel/webpanel.h:257
315319
msgid "Comment font family"
316320
msgstr "注释字体族"
317321

318-
#: webpanel/webpanel.h:253
322+
#: webpanel/webpanel.h:259
319323
msgid "Comment font size"
320324
msgstr "注释字号"
321325

322-
#: webpanel/webpanel.h:256
326+
#: webpanel/webpanel.h:262
323327
msgid "Preedit font family"
324328
msgstr "预编辑字体族"
325329

326-
#: webpanel/webpanel.h:258
330+
#: webpanel/webpanel.h:264
327331
msgid "Preedit font size"
328332
msgstr "预编辑字号"
329333

330-
#: webpanel/webpanel.h:260
334+
#: webpanel/webpanel.h:266
331335
msgid "User font dir"
332336
msgstr "用户字体目录"
333337

334-
#: webpanel/webpanel.h:261
338+
#: webpanel/webpanel.h:267
335339
msgid "System font dir"
336340
msgstr "系统字体目录"
337341

338-
#: webpanel/webpanel.h:266
342+
#: webpanel/webpanel.h:272
339343
msgid "Style"
340344
msgstr "样式"
341345

342-
#: webpanel/webpanel.h:272
346+
#: webpanel/webpanel.h:278
343347
msgid "Mark style"
344348
msgstr "标记样式"
345349

346-
#: webpanel/webpanel.h:273
350+
#: webpanel/webpanel.h:279
347351
msgid "Mark text"
348352
msgstr "标记文本"
349353

350-
#: webpanel/webpanel.h:275
354+
#: webpanel/webpanel.h:281
351355
msgid "Hover behavior"
352356
msgstr "悬停行为"
353357

354-
#: webpanel/webpanel.h:281
358+
#: webpanel/webpanel.h:287
355359
msgid "Border width (px)"
356360
msgstr "边框宽度(px)"
357361

358-
#: webpanel/webpanel.h:284
362+
#: webpanel/webpanel.h:290
359363
msgid "Border radius (px)"
360364
msgstr "边框半径(px)"
361365

362-
#: webpanel/webpanel.h:285
366+
#: webpanel/webpanel.h:291
363367
msgid "Margin (px)"
364368
msgstr "外边距(px)"
365369

366-
#: webpanel/webpanel.h:288
370+
#: webpanel/webpanel.h:294
367371
msgid "Highlight radius (px)"
368372
msgstr "高亮半径(px)"
369373

370-
#: webpanel/webpanel.h:291
374+
#: webpanel/webpanel.h:297
371375
msgid "Top padding (px)"
372376
msgstr "顶填充(px)"
373377

374-
#: webpanel/webpanel.h:293
378+
#: webpanel/webpanel.h:299
375379
msgid "Right padding (px)"
376380
msgstr "右填充(px)"
377381

378-
#: webpanel/webpanel.h:295
382+
#: webpanel/webpanel.h:301
379383
msgid "Bottom padding (px)"
380384
msgstr "底填充(px)"
381385

382-
#: webpanel/webpanel.h:298
386+
#: webpanel/webpanel.h:304
383387
msgid "Left padding (px)"
384388
msgstr "左填充(px)"
385389

386-
#: webpanel/webpanel.h:300
390+
#: webpanel/webpanel.h:306
387391
msgid "Gap between label, text and comment (px)"
388392
msgstr "标签、文本、注释间隔(px)"
389393

390-
#: webpanel/webpanel.h:303
394+
#: webpanel/webpanel.h:309
391395
msgid "Vertical minimum width (px)"
392396
msgstr "垂直时最小宽度(px)"
393397

394-
#: webpanel/webpanel.h:306
398+
#: webpanel/webpanel.h:312
395399
msgid "Horizontal divider width (px)"
396400
msgstr "水平分隔线宽度(px)"
397401

398-
#: webpanel/webpanel.h:315
402+
#: webpanel/webpanel.h:321
399403
msgid "User CSS"
400404
msgstr "用户 CSS"
401405

402-
#: webpanel/webpanel.h:316
406+
#: webpanel/webpanel.h:322
403407
msgid "Copy HTML"
404408
msgstr "复制 HTML"
405409

406-
#: webpanel/webpanel.h:317
410+
#: webpanel/webpanel.h:323
407411
msgid "Plugin dir"
408412
msgstr "插件目录"
409413

410-
#: webpanel/webpanel.h:319
414+
#: webpanel/webpanel.h:325
411415
msgid "I know there may be risks for using plugins"
412416
msgstr "我知道使用插件可能有风险"
413417

414-
#: webpanel/webpanel.h:322
418+
#: webpanel/webpanel.h:328
415419
msgid "Plugins"
416420
msgstr "插件"
417421

418-
#: webpanel/webpanel.h:324
422+
#: webpanel/webpanel.h:330
419423
msgid "Dangerous API for JavaScript plugins"
420424
msgstr "用于 JavaScript 插件的危险 API"
421425

422-
#: webpanel/webpanel.h:327
426+
#: webpanel/webpanel.h:333
423427
msgid "Basic"
424428
msgstr "基础"
425429

426-
#: webpanel/webpanel.h:328
430+
#: webpanel/webpanel.h:334
427431
msgid "Light mode"
428432
msgstr "浅色模式"
429433

430-
#: webpanel/webpanel.h:329
434+
#: webpanel/webpanel.h:335
431435
msgid "Dark mode"
432436
msgstr "深色模式"
433437

434-
#: webpanel/webpanel.h:330
438+
#: webpanel/webpanel.h:336
435439
msgid "Typography"
436440
msgstr "版式"
437441

438-
#: webpanel/webpanel.h:331
442+
#: webpanel/webpanel.h:337
439443
msgid "Scroll mode"
440444
msgstr "卷轴模式"
441445

442-
#: webpanel/webpanel.h:332
446+
#: webpanel/webpanel.h:338
443447
msgid "Background"
444448
msgstr "背景"
445449

446-
#: webpanel/webpanel.h:333
450+
#: webpanel/webpanel.h:339
447451
msgid "Font"
448452
msgstr "字体"
449453

450-
#: webpanel/webpanel.h:334
454+
#: webpanel/webpanel.h:340
451455
msgid "Cursor"
452456
msgstr "光标"
453457

454-
#: webpanel/webpanel.h:335
458+
#: webpanel/webpanel.h:341
455459
msgid "Highlight"
456460
msgstr "高亮"
457461

458-
#: webpanel/webpanel.h:336
462+
#: webpanel/webpanel.h:342
459463
msgid "Size"
460464
msgstr "尺寸"
461465

462-
#: webpanel/webpanel.h:337
466+
#: webpanel/webpanel.h:343
463467
msgid "Advanced"
464468
msgstr "高级"

webpanel/webpanel.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,23 @@ WebPanel::WebPanel(Instance *instance)
162162
return keyEvent.filterAndAccept();
163163
}
164164
if (scrollState_ == candidate_window::scroll_state_t::scrolling) {
165-
static const std::vector<
166-
std::pair<Key, candidate_window::scroll_key_action_t>>
167-
selectMap = {
168-
{Key(FcitxKey_1),
169-
candidate_window::scroll_key_action_t::one},
170-
{Key(FcitxKey_2),
171-
candidate_window::scroll_key_action_t::two},
172-
{Key(FcitxKey_3),
173-
candidate_window::scroll_key_action_t::three},
174-
{Key(FcitxKey_4),
175-
candidate_window::scroll_key_action_t::four},
176-
{Key(FcitxKey_5),
177-
candidate_window::scroll_key_action_t::five},
178-
{Key(FcitxKey_6),
179-
candidate_window::scroll_key_action_t::six},
165+
static const std::vector<candidate_window::scroll_key_action_t>
166+
selectActions = {
167+
candidate_window::scroll_key_action_t::one,
168+
candidate_window::scroll_key_action_t::two,
169+
candidate_window::scroll_key_action_t::three,
170+
candidate_window::scroll_key_action_t::four,
171+
candidate_window::scroll_key_action_t::five,
172+
candidate_window::scroll_key_action_t::six,
180173
};
181-
for (const auto &pair : selectMap) {
182-
if (key.check(pair.first)) {
183-
if (keyEvent.isRelease()) {
184-
return;
185-
}
186-
window_->scroll_key_action(pair.second);
187-
return keyEvent.filterAndAccept();
174+
if (int i =
175+
key.keyListIndex(*config_.scrollMode->selectCandidate);
176+
i >= 0 && i < selectActions.size()) {
177+
if (keyEvent.isRelease()) {
178+
return;
188179
}
180+
window_->scroll_key_action(selectActions[i]);
181+
return keyEvent.filterAndAccept();
189182
}
190183
const std::vector<std::pair<
191184
Option<KeyList>, candidate_window::scroll_key_action_t>>

webpanel/webpanel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ FCITX_CONFIGURATION(
207207
Option<KeyList> pageDown{
208208
this, "PageDown", _("Page down"), {Key(FcitxKey_Page_Down)}};
209209
Option<KeyList> commit{this, "Commit", _("Commit"), {Key(FcitxKey_space)}};
210+
Option<KeyList> selectCandidate{this,
211+
"SelectCandidate",
212+
_("Select candidate"),
213+
{Key(FcitxKey_1), Key(FcitxKey_2),
214+
Key(FcitxKey_3), Key(FcitxKey_4),
215+
Key(FcitxKey_5), Key(FcitxKey_6)}};
210216
Option<bool> optimizeForHyperKey{this, "OptimizeForHyperKey",
211217
_("Optimize for Hyper key"), true};);
212218

0 commit comments

Comments
 (0)