From 4ac962ef7ebb455d6ecea44fa4aad88fc14f229b Mon Sep 17 00:00:00 2001 From: Shingo Date: Sun, 12 Jan 2025 22:32:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(cold=5Fword=5Fdrop):=20=E5=86=99=E5=85=A5?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=92=8C=E5=85=BC=E5=AE=B9=E6=80=A7=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20(#1138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(cold_word_drop): 写入记录的文件夹名称错误 * 保证 processor.lua 旧版的兼容性 --- lua/cold_word_drop/filter.lua | 18 +++++++++++------- lua/cold_word_drop/processor.lua | 31 ++++++++++++++++++------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lua/cold_word_drop/filter.lua b/lua/cold_word_drop/filter.lua index 0287cea6e..196248790 100644 --- a/lua/cold_word_drop/filter.lua +++ b/lua/cold_word_drop/filter.lua @@ -2,19 +2,23 @@ -- 在 engine/processors 增加 - lua_processor@cold_word_drop.processor -- 在 engine/filters 增加 - lua_filter@cold_word_drop.filter -- 在 key_binder 增加快捷键: --- turn_down_cand: "Control+j" # 匹配当前输入码后隐藏指定的候选字词 或候选词条放到第四候选位置 +-- reduce_freq_cand: "Control+j" # 匹配当前输入码后隐藏指定的候选字词 或候选词条放到第四候选位置 -- drop_cand: "Control+d" # 强制删词, 无视输入的编码 -- get_record_filername() 函数中仅支持了 Windows、macOS、Linux local filter = {} function filter.init(env) - local engine = env.engine - local config = engine.schema.config - env.word_reduce_idx = config:get_int("cold_word_reduce/idx") or 4 - env.drop_words = require("cold_word_drop.drop_words") or {} - env.hide_words = require("cold_word_drop.hide_words") or {} - env.reduce_freq_words = require("cold_word_drop.reduce_freq_words") or {} + local engine = env.engine + local config = engine.schema.config + local _sd, drop_words = pcall(require, "cold_word_drop/drop_words") + local _sh, hide_words = pcall(require, "cold_word_drop/hide_words") + local _st, turn_down_words = pcall(require, "cold_word_drop/turn_down_words") + local _sr, reduce_freq_words = pcall(require, "cold_word_drop/reduce_freq_words") + env.word_reduce_idx = config:get_int("cold_word_reduce/idx") or 4 + env.drop_words = _sd and drop_words or {} + env.hide_words = _sh and hide_words or {} + env.reduce_freq_words = (_st and turn_down_words) or (_sr and reduce_freq_words) or {} end function filter.func(input, env) diff --git a/lua/cold_word_drop/processor.lua b/lua/cold_word_drop/processor.lua index 96c131955..742bf4493 100644 --- a/lua/cold_word_drop/processor.lua +++ b/lua/cold_word_drop/processor.lua @@ -2,8 +2,8 @@ -- 在 engine/processors 增加 - lua_processor@cold_word_drop.processor -- 在 engine/filters 增加 - lua_filter@cold_word_drop.filter -- 在 key_binder 增加快捷键: --- turn_down_cand: "Control+j" # 匹配当前输入码后隐藏指定的候选字词 或候选词条放到第四候选位置 --- drop_cand: "Control+d" # 强制删词, 无视输入的编码 +-- reduce_freq_cand: "Control+j" # 匹配当前输入码后隐藏指定的候选字词 或候选词条放到第四候选位置 +-- drop_cand: "Control+d" # 强制删词, 无视输入的编码 -- get_record_filername() 函数中仅支持了 Windows、macOS、Linux require("cold_word_drop.string") @@ -16,12 +16,12 @@ local function get_record_filername(record_type) local user_distribute_name = rime_api:get_distribution_code_name() if user_distribute_name:lower():match("weasel") then path_sep = [[\]] end if user_distribute_name:lower():match("ibus") then - return string.format("%s/rime/lua/cold_word_records/%s_words.lua", + return string.format("%s/rime/lua/cold_word_drop/%s_words.lua", os.getenv("HOME") .. "/.config/ibus", record_type ) else - local file_path = string.format("%s/lua/cold_word_records/%s_words.lua", user_data_dir, record_type) + local file_path = string.format("%s/lua/cold_word_drop/%s_words.lua", user_data_dir, record_type) return file_path:gsub("/", path_sep) end end @@ -74,15 +74,20 @@ local function append_word_to_droplist(env, ctx, action_type) end function processor.init(env) - local engine = env.engine - local config = engine.schema.config - env.drop_cand_key = config:get_string("key_binder/drop_cand") or "Control+d" - env.hide_cand_key = config:get_string("key_binder/hide_cand") or "Control+x" - env.reduce_cand_key = config:get_string("key_binder/reduce_freq_cand") or "Control+j" - env.drop_words = require("cold_word_drop.drop_words") or {} - env.hide_words = require("cold_word_drop.hide_words") or {} - env.reduce_freq_words = require("cold_word_drop.reduce_freq_words") or {} - env.tbls = { + local engine = env.engine + local config = engine.schema.config + local _sd, drop_words = pcall(require, "cold_word_drop/drop_words") + local _sh, hide_words = pcall(require, "cold_word_drop/hide_words") + local _st, turn_down_words = pcall(require, "cold_word_drop/turn_down_words") + local _sr, reduce_freq_words = pcall(require, "cold_word_drop/reduce_freq_words") + env.drop_words = _sd and drop_words or {} + env.hide_words = _sh and hide_words or {} + env.reduce_freq_words = (_st and turn_down_words) or (_sr and reduce_freq_words) or {} + env.drop_cand_key = config:get_string("key_binder/drop_cand") or "Control+d" + env.hide_cand_key = config:get_string("key_binder/hide_cand") or "Control+x" + env.turn_down_cand_key = config:get_string("key_binder/turn_down_cand") or nil + env.reduce_cand_key = env.turn_down_cand_key or config:get_string("key_binder/reduce_freq_cand") or "Control+j" + env.tbls = { ["drop_list"] = env.drop_words, ["hide_list"] = env.hide_words, ["reduce_freq_list"] = env.reduce_freq_words,