Skip to content

Commit

Permalink
fix(cold_word_drop): 写入记录的文件夹名称和兼容性修复 (#1138)
Browse files Browse the repository at this point in the history
* fix(cold_word_drop): 写入记录的文件夹名称错误
* 保证 processor.lua 旧版的兼容性
  • Loading branch information
boomker authored Jan 12, 2025
1 parent 5af5fac commit 4ac962e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
18 changes: 11 additions & 7 deletions lua/cold_word_drop/filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 18 additions & 13 deletions lua/cold_word_drop/processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4ac962e

Please sign in to comment.