Skip to content

Commit

Permalink
支持在用户词典里删除词条
Browse files Browse the repository at this point in the history
  • Loading branch information
amorphobia committed Jan 27, 2021
1 parent ceaec45 commit 6ee1bac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
19 changes: 18 additions & 1 deletion lua/openfly_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ local function detect_os()
return sys
end

return { detect_os = detect_os }
local function status(context)
local stat = {}
local composition = context.composition
stat.always = true
stat.composing = context:is_composing()
stat.empty = not stat.composing
stat.has_menu = context:has_menu()
stat.paging = not composition.empty() and composition:back():has_tag("paging")
return stat
end

return {
detect_os = detect_os,
status = status,
kRejected = 0,
kAccepted = 1,
kNoop = 2
}
22 changes: 22 additions & 0 deletions lua/openfly_deletion_filter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local function filter(input)
local candidates = {}
local del_text = {}
local index_text = {}
for cand in input:iter() do
table.insert(index_text, cand.text)
candidates[cand.text] = cand
if cand:get_genuine().comment == "[删]" then
table.insert(del_text, cand.text)
end
end
for i, t in pairs(del_text) do
candidates[t] = nil
end
for i, t in pairs(index_text) do
if candidates[t] ~= nil then
yield(candidates[t])
end
end
end

return filter
3 changes: 1 addition & 2 deletions lua/openfly_shortcut_processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ local command = {
local function processor(key, env)
local engine = env.engine
local context = engine.context
local kNoop = 2

local sys = common.detect_os()
local cmd = command[sys][context.input]
if cmd ~= nil then
os.execute(cmd)
context:clear()
end
return kNoop
return common.kNoop
end

return processor
1 change: 1 addition & 0 deletions openfly.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ engine:
- history_translator@history
filters:
- lua_filter@openfly_hint_filter
- lua_filter@openfly_deletion_filter
- simplifier
- simplifier@simplification
- uniquifier
Expand Down

0 comments on commit 6ee1bac

Please sign in to comment.