Skip to content

Commit 6ee1bac

Browse files
committed
支持在用户词典里删除词条
1 parent ceaec45 commit 6ee1bac

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

lua/openfly_common.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,21 @@ local function detect_os()
1818
return sys
1919
end
2020

21-
return { detect_os = detect_os }
21+
local function status(context)
22+
local stat = {}
23+
local composition = context.composition
24+
stat.always = true
25+
stat.composing = context:is_composing()
26+
stat.empty = not stat.composing
27+
stat.has_menu = context:has_menu()
28+
stat.paging = not composition.empty() and composition:back():has_tag("paging")
29+
return stat
30+
end
31+
32+
return {
33+
detect_os = detect_os,
34+
status = status,
35+
kRejected = 0,
36+
kAccepted = 1,
37+
kNoop = 2
38+
}

lua/openfly_deletion_filter.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
local function filter(input)
2+
local candidates = {}
3+
local del_text = {}
4+
local index_text = {}
5+
for cand in input:iter() do
6+
table.insert(index_text, cand.text)
7+
candidates[cand.text] = cand
8+
if cand:get_genuine().comment == "[删]" then
9+
table.insert(del_text, cand.text)
10+
end
11+
end
12+
for i, t in pairs(del_text) do
13+
candidates[t] = nil
14+
end
15+
for i, t in pairs(index_text) do
16+
if candidates[t] ~= nil then
17+
yield(candidates[t])
18+
end
19+
end
20+
end
21+
22+
return filter

lua/openfly_shortcut_processor.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ local command = {
2222
local function processor(key, env)
2323
local engine = env.engine
2424
local context = engine.context
25-
local kNoop = 2
2625

2726
local sys = common.detect_os()
2827
local cmd = command[sys][context.input]
2928
if cmd ~= nil then
3029
os.execute(cmd)
3130
context:clear()
3231
end
33-
return kNoop
32+
return common.kNoop
3433
end
3534

3635
return processor

openfly.schema.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ engine:
5151
- history_translator@history
5252
filters:
5353
- lua_filter@openfly_hint_filter
54+
- lua_filter@openfly_deletion_filter
5455
- simplifier
5556
- simplifier@simplification
5657
- uniquifier

0 commit comments

Comments
 (0)