From 6ee1bacdcc20fdf93f10793f8c5c942fb42b4425 Mon Sep 17 00:00:00 2001 From: amorphobia Date: Wed, 27 Jan 2021 16:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AF=8D=E5=85=B8=E9=87=8C=E5=88=A0=E9=99=A4=E8=AF=8D=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/openfly_common.lua | 19 ++++++++++++++++++- lua/openfly_deletion_filter.lua | 22 ++++++++++++++++++++++ lua/openfly_shortcut_processor.lua | 3 +-- openfly.schema.yaml | 1 + 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 lua/openfly_deletion_filter.lua diff --git a/lua/openfly_common.lua b/lua/openfly_common.lua index 7e8ea9c..20cd2a0 100644 --- a/lua/openfly_common.lua +++ b/lua/openfly_common.lua @@ -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 +} diff --git a/lua/openfly_deletion_filter.lua b/lua/openfly_deletion_filter.lua new file mode 100644 index 0000000..7e76f27 --- /dev/null +++ b/lua/openfly_deletion_filter.lua @@ -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 diff --git a/lua/openfly_shortcut_processor.lua b/lua/openfly_shortcut_processor.lua index dac2b8a..a596a29 100644 --- a/lua/openfly_shortcut_processor.lua +++ b/lua/openfly_shortcut_processor.lua @@ -22,7 +22,6 @@ 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] @@ -30,7 +29,7 @@ local function processor(key, env) os.execute(cmd) context:clear() end - return kNoop + return common.kNoop end return processor diff --git a/openfly.schema.yaml b/openfly.schema.yaml index 83bb4c3..3fb9704 100644 --- a/openfly.schema.yaml +++ b/openfly.schema.yaml @@ -51,6 +51,7 @@ engine: - history_translator@history filters: - lua_filter@openfly_hint_filter + - lua_filter@openfly_deletion_filter - simplifier - simplifier@simplification - uniquifier