Skip to content

Commit 626d100

Browse files
committed
用 lua 实现类似多多输入法 newkey 的功能
1 parent e95d8f9 commit 626d100

4 files changed

+80
-34
lines changed

lua/openfly_hint_filter.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ local function filter(input)
1010
yield(cand)
1111
else
1212
local original_comment = cand:get_genuine().comment
13-
yield(Candidate(cand.type, cand.start, cand._end, word, original_comment .. comment))
13+
if word:sub(1,1) ~= "$" then
14+
yield(Candidate(cand.type, cand.start, cand._end, word, original_comment .. comment))
15+
else
16+
yield(Candidate(word, cand.start, cand._end, original_comment .. comment, ""))
17+
end
1418
end
1519
end
1620
end

lua/openfly_shortcut_processor.lua

+25-8
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,32 @@ local function processor(key, env)
3030
local context = env.engine.context
3131
local sys = common.detect_os()
3232
if key:release() or key:alt() then return common.kNoop end
33-
local index = common.select_index(env, key) + 1
34-
if index <= 0 then return common.kNoop end
35-
local cmd = command[sys][context.input][index]
36-
if cmd ~= nil then
37-
os.execute(cmd)
38-
context:clear()
39-
return common.kAccepted
33+
local index = common.select_index(env, key)
34+
if index < 0 then return common.kNoop end
35+
if command[sys][context.input] ~= nil then
36+
local cmd = command[sys][context.input][index+1]
37+
if cmd ~= nil then
38+
os.execute(cmd)
39+
context:clear()
40+
return common.kAccepted
41+
end
4042
end
41-
return common.kNoop
43+
44+
local comp = context.composition
45+
if comp.empty == nil then return common.kNoop end
46+
if comp:empty() then return common.kNoop end
47+
local seg = comp:back()
48+
if seg == nil or seg.menu == nil or seg:has_tag("raw") then return common.kNoop end
49+
local page_size = env.engine.schema.page_size
50+
if index >= page_size then return common.kNoop end
51+
local page_start = math.floor(seg.selected_index / page_size) * page_size
52+
local cand = seg:get_candidate_at(page_start + index)
53+
if cand == nil then return common.kNoop end
54+
if cand.type:sub(1,1) ~= "$" then return common.kNoop end
55+
local new_input = string.match(cand.type, "%$(%w+)")
56+
if new_input == nil or new_input == "" then return common.kNoop end
57+
context.input = new_input
58+
return common.kAccepted
4259
end
4360

4461
return processor

lua/openfly_shortcut_translator.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ local labels = {
1919
}
2020
}
2121

22-
local function translator(input, seg, env)
22+
local function translator(input, seg)
2323
local sys = common.detect_os()
2424
local lbls = labels[sys][input]
25+
if lbls == nil then return end
2526
for i, lbl in pairs(lbls) do
2627
yield(Candidate("shortcut", seg.start, seg._end, lbl, ""))
2728
end

openfly.symbols.dict.yaml

+48-24
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,31 @@ use_preset_vocabulary: false
106106
辶 obz 98
107107
” oc
108108
、 od
109-
标点d ofb
109+
$ofbd`bd(标点)、,。 of
110+
$ofpp`pp(偏旁)亻彳讠 of
111+
$ofdw`dw(单位)㎎㎏㎜ of
112+
$ofpy`py(拼音)āōē of
113+
$ofjt`jt(箭头)←→↑ of
114+
$ofyu`yu(圆圈数字)①②③ of
115+
$ofku`ku(括号数字)⑴⑵⑶ of
116+
$ofdu`du(点号数字)⒈⒉⒊ of
117+
$ofvu`vu(中文数字)㈠㈡㈢ of
118+
$ofld`ld(罗马大写)ⅠⅡⅢ of
119+
$oflx`lx(罗马小写)ⅰⅱⅲ of
120+
$ofub`ub(上标)¹²³ of
121+
$ofxb`xb(下标)₁₂₃ of
122+
$oftu`tu(特殊符号)℃°‰ of
123+
$ofux`ux(数学符号)+-< of
124+
$ofhb`hb(货币符号)€$¢ of
125+
$ofvb`vb(制表符号)┌└┐ of
126+
$ofvy`vy(注音符号)ㄅㄆㄇ of
127+
$ofxd`xd(希腊大写)ΑΒΓ of
128+
$ofxx`xx(希腊小写)αβγ of
129+
$ofed`ed(俄文大写)АБВ of
130+
$ofex`ex(俄文小写)абв of
131+
$ofrd`rd(日文大写)ァアィ of
132+
$ofrx`rx(日文小写)ぁあぃ of
133+
$ofbd`d(标点)、,。 ofb
110134
“” ofbd 100
111135
() ofbd 99
112136
《》 ofbd 98
@@ -141,8 +165,8 @@ use_preset_vocabulary: false
141165
' ofbd 69
142166
` ofbd 68
143167
| ofbd 67
144-
点号数字u ofd 100
145-
单位w ofd 99
168+
$ofdw`w(单位)㎎㎏㎜ ofd 100
169+
$ofdu`u(点号数字)⒈⒉⒊ ofd 99
146170
⒈ ofdu 100
147171
⒉ ofdu 99
148172
⒊ ofdu 98
@@ -177,8 +201,8 @@ nm ofdw 94
177201
㏑ ofdw 89
178202
㏒ ofdw 88
179203
㏕ ofdw 87
180-
俄文大写d ofe 100
181-
俄文小写x ofe 99
204+
$ofed`d(俄文大写)АБВ ofe 100
205+
$ofex`x(俄文小写)абв ofe 99
182206
А ofed 100
183207
Б ofed 99
184208
В ofed 98
@@ -245,7 +269,7 @@ nm ofdw 94
245269
ю ofex 70
246270
я ofex 69
247271
ё ofex 68
248-
货币符号b ofh
272+
$ofhb`b(货币符号)€$¢ ofh
249273
€ ofhb 100
250274
$ ofhb 99
251275
¢ ofhb 98
@@ -254,7 +278,7 @@ $ ofhb 99
254278
¥ ofhb 94
255279
¥ ofhb 93
256280
฿ ofhb 92
257-
箭头t ofj
281+
$ofjt`t(箭头)←→↑ ofj
258282
← ofjt 100
259283
→ ofjt 99
260284
↑ ofjt 98
@@ -265,7 +289,7 @@ $ ofhb 99
265289
↖ ofjt 93
266290
↔ ofjt 92
267291
↕ ofjt 91
268-
括号数字u ofk
292+
$ofku`u(括号数字)⑴⑵⑶ ofk
269293
⑴ ofku 100
270294
⑵ ofku 99
271295
⑶ ofku 98
@@ -286,8 +310,8 @@ $ ofhb 99
286310
⒅ ofku 83
287311
⒆ ofku 82
288312
⒇ ofku 81
289-
罗马大写d ofl 100
290-
罗马小写x ofl 99
313+
$ofld`d(罗马大写)ⅠⅡⅢ ofl 100
314+
$oflx`x(罗马小写)ⅰⅱⅲ ofl 99
291315
Ⅰ ofld 100
292316
Ⅱ ofld 99
293317
Ⅲ ofld 98
@@ -310,8 +334,8 @@ $ ofhb 99
310334
ⅷ oflx 93
311335
ⅸ oflx 92
312336
ⅹ oflx 91
313-
偏旁p ofp 100
314-
拼音y ofp 99
337+
$ofpp`p(偏旁)亻彳讠 ofp 100
338+
$ofpy`y(拼音)āōē ofp 99
315339
勹 ofpp 100
316340
灬 ofpp 99
317341
冫 ofpp 98
@@ -379,8 +403,8 @@ $ ofhb 99
379403
ú ofpy 77
380404
ǔ ofpy 76
381405
ù ofpy 75
382-
日文大写d ofr 100
383-
日文小写x ofr 99
406+
$ofrd`d(日文大写)ァアィ ofr 100
407+
$ofrx`x(日文小写)ぁあぃ ofr 99
384408
ァ ofrd 100
385409
ア ofrd 99
386410
ィ ofrd 98
@@ -557,7 +581,7 @@ $ ofhb 99
557581
゜ ofrx 16
558582
ゝ ofrx 15
559583
ゞ ofrx 14
560-
特殊符号u oft
584+
$oftu`u(特殊符号)℃°‰ oft
561585
℃ oftu 100
562586
° oftu 99
563587
‰ oftu 98
@@ -585,8 +609,8 @@ $ ofhb 99
585609
^ oftu 76
586610
_ oftu 75
587611
 ̄ oftu 74
588-
上标b ofu 100
589-
数学符号x ofu 99
612+
$ofub`b(上标)¹²³ ofu 100
613+
$ofux`x(数学符号)+-< ofu 99
590614
¹ ofub 100
591615
² ofub 99
592616
³ ofub 98
@@ -649,9 +673,9 @@ $ ofhb 99
649673
⊙ ofux 58
650674
⊥ ofux 57
651675
⊿ ofux 56
652-
中文数字u ofv 100
653-
制表符号b ofv 99
654-
注音符号y ofv 98
676+
$ofvu`u(中文数字)㈠㈡㈢ ofv 100
677+
$ofvb`b(制表符号)┌└┐ ofv 99
678+
$ofvy`y(注音符号)ㄅㄆㄇ ofv 98
655679
┌ ofvb 100
656680
└ ofvb 99
657681
┐ ofvb 98
@@ -721,9 +745,9 @@ $ ofhb 99
721745
ㄤ ofvy 66
722746
ㄥ ofvy 65
723747
ㄦ ofvy 64
724-
下标b ofx 100
725-
希腊大写d ofx 99
726-
希腊小写x ofx 98
748+
$ofxb`b(下标)₁₂₃ ofx 100
749+
$ofxd`d(希腊大写)ΑΒΓ ofx 99
750+
$ofxx`x(希腊小写)αβγ ofx 98
727751
₁ ofxb 100
728752
₂ ofxb 99
729753
₃ ofxb 98
@@ -789,7 +813,7 @@ $ ofhb 99
789813
χ ofxx 79
790814
ψ ofxx 78
791815
ω ofxx 77
792-
圆圈数字u ofy
816+
$ofyu`u(圆圈数字)①②③ ofy
793817
① ofyu 100
794818
② ofyu 99
795819
③ ofyu 98

0 commit comments

Comments
 (0)