From 06b86205dbc160fac8ee37ec2859f96e9cc0083b Mon Sep 17 00:00:00 2001 From: amzxyz Date: Fri, 2 Jan 2026 11:02:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BB=85=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E6=A8=A1=E5=BC=8F=E4=B8=8B=E6=94=AF=E6=8C=81=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E8=8B=B1=E6=96=87=E5=8F=A5=E5=AD=90=EF=BC=8C=E4=B8=89?= =?UTF-8?q?=E5=85=83=E5=BC=80=E5=85=B3=E7=BB=84=E7=9A=84=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=94=AE=E4=B9=9F=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=B8=B8=E6=80=81?= =?UTF-8?q?=E5=8C=96Shift+space=E4=B8=8D=E7=94=A8=E9=9D=9E=E8=A6=81?= =?UTF-8?q?=E5=9C=A8=E8=BE=93=E5=85=A5=E4=B8=AD=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom/wanxiang_pro.schema.yaml | 11 ++- default.yaml | 8 +-- dicts/jichu.dict.yaml | 33 +++++---- lua/super_filter.lua | 119 +++++++++++++++++++++++++++----- wanxiang.schema.yaml | 13 ++-- wanxiang_t9.schema.yaml | 4 +- 6 files changed, 134 insertions(+), 54 deletions(-) diff --git a/custom/wanxiang_pro.schema.yaml b/custom/wanxiang_pro.schema.yaml index 99132f8..7567850 100644 --- a/custom/wanxiang_pro.schema.yaml +++ b/custom/wanxiang_pro.schema.yaml @@ -101,8 +101,8 @@ engine: - reverse_lookup_filter@radical_reverse_lookup #部件拆字滤镜,放在super_comment前面,进一步被超级注释处理以获得拼音编码的提示 - lua_filter@*auto_phrase #comment前,无感造词,关闭调频的时候将汉字写入次翻译器,当没有英文候选的时候追加\上屏可完成英文造词 - lua_filter@*super_lookup #comment前,字词输入中反查辅助筛选 + - lua_filter@*super_filter #comment前,功能太多详见Lua文件 - lua_filter@*super_comment_preedit #OpenCC前,超级注释模块、超级preedit,支持错词提示、辅助码显示,部件组字读音注释,有声调、无声调全拼编码的转换,支持个性化配置和关闭相应的功能,详情搜索super_comment_preedit进行详细配置 - - lua_filter@*super_filter #功能太多详见Lua文件 - simplifier@emoji #Emoji滤镜 - simplifier@s2t #简繁切换通繁 - simplifier@s2tw #简繁切换台繁 @@ -396,10 +396,8 @@ wanxiang_mixedcode: dictionary: wanxiang_mixedcode user_dict: en enable_completion: true - enable_sentence: false + enable_sentence: true initial_quality: 2 - comment_format: - - xform/^.+$// # Emoji emoji: @@ -582,9 +580,8 @@ key_binder: # 通过快捷键Control+g开启字符集过滤 - { when: has_menu, accept: "Control+g", toggle: charset_filter } - { when: composing, accept: "Control+g", toggle: charset_filter } -#通过快捷键Control+q切换中文、英文、混合模式 - - { when: has_menu, accept: "Control+q", toggle: zh_only } - - { when: composing, accept: "Control+q", toggle: zh_only } +#通过快捷键Shift+space开启输入模式切换 + - { when: always, accept: "Shift+space", toggle: zh_only } # 使用 tab 在不同音节之间跳转 - { when: has_menu, accept: "Tab", send: "Control+Right" } - { when: composing, accept: "Tab", send: "Control+Right" } diff --git a/default.yaml b/default.yaml index 2a9b4ce..e8fbf47 100644 --- a/default.yaml +++ b/default.yaml @@ -41,6 +41,8 @@ switcher: - tone_hint - full_pinyin - chinese_english + - zh_only + - en_only - search_single_char fold_options: true # 呼出时是否折叠,多方案时建议折叠 true ,一个方案建议展开 false abbreviate_options: true # 折叠时是否缩写选项 @@ -75,12 +77,6 @@ ascii_composer: # 此处配置较为通用的选项,各方案中另增加了和方案功能绑定的 patterns。 recognizer: patterns: - email: "^[A-Za-z][-_.0-9A-Za-z]*@.*$" # email @ 之后不上屏 - url: "^(www[.]|https?:|ftp[.:]|mailto:|file:).*$|^[a-z]+[.].+$" # URL - underscore: "^[A-Za-z]+_.*" # 下划线不上屏 - # url_2: "^[A-Za-z]+[.].*" # 句号不上屏,支持 google.com abc.txt 等网址或文件名,使用句号翻页时需要注释掉 - # colon: "^[A-Za-z]+:.*" # 冒号不上屏 - # 快捷键 key_binder: diff --git a/dicts/jichu.dict.yaml b/dicts/jichu.dict.yaml index c777b48..298e946 100644 --- a/dicts/jichu.dict.yaml +++ b/dicts/jichu.dict.yaml @@ -93080,6 +93080,7 @@ sort: by_weight 颇感 pō gǎn 482 颇高 pō gāo 581 破格 pò gé 478 +破歌 pò gē 411 坡跟 pō gēn 408 破功 pò gōng 388 破瓜 pò guā 277 @@ -107526,7 +107527,6 @@ sort: by_weight 沈飞 shěn fēi 415 神飞 shén fēi 259 身份 shēn fèn 796 -身分 shēn fèn 612 砷粉 shēn fěn 201 神风 shén fēng 480 神锋 shén fēng 392 @@ -236605,6 +236605,7 @@ sort: by_weight 持续了 chí xù le 144 持续力 chí xù lì 237 持续期 chí xù qī 47 +持续是 chí xù shì 298 持续时 chí xù shí 114 持续式 chí xù shì 27 持续性 chí xù xìng 306 @@ -398071,9 +398072,8 @@ sort: by_weight 会坐上 huì zuò shàng 377 会做什 huì zuò shén 292 会坐视 huì zuò shì 396 +会作诗 huì zuò shī 225 会做事 huì zuò shì 182 -会做诗 huì zuò shī 135 -会作诗 huì zuò shī 125 会作死 huì zuō sǐ 361 会做他 huì zuò tā 278 会做太 huì zuò tài 274 @@ -401363,7 +401363,7 @@ sort: by_weight 几丁虫 jǐ dīng chóng 76 既定的 jì dìng de 276 积顶点 jī dǐng diǎn 78 -机顶盒 jī dǐng hé 308 +机顶盒 jī dǐng hé 508 吉丁阶 jí dīng jiē 62 机顶麦 jī dǐng mài 82 既定时 jì dìng shí 241 @@ -446436,6 +446436,7 @@ sort: by_weight 开始画 kāi shǐ huà 208 开始化 kāi shǐ huà 7 开始记 kāi shǐ jì 144 +开始加 kāi shǐ jiā 297 开市价 kāi shì jià 156 开始交 kāi shǐ jiāo 169 开始就 kāi shǐ jiù 326 @@ -542600,6 +542601,8 @@ sort: by_weight 弄了吧 nòng le ba 168 浓了吧 nóng le ba 156 弄了个 nòng le gè 258 +弄了些 nòng le xiē 306 +浓了些 nóng le xiē 254 农乐园 nóng lè yuán 140 弄愣了 nòng lèng le 109 农历年 nóng lì nián 218 @@ -561104,10 +561107,11 @@ sort: by_weight 千金女 qiān jīn nǚ 44 千金片 qiān jīn piàn 321 千金裘 qiān jīn qiú 164 -潜进去 qián jìn qù 218 +嵌进去 qiàn jìn qù 361 +潜进去 qián jìn qù 268 +迁进去 qiān jìn qù 220 +前进区 qián jìn qū 195 前金区 qián jīn qū 168 -迁进去 qiān jìn qù 120 -前进区 qián jìn qū 115 千金躯 qiān jīn qū 86 前进三 qián jìn sān 129 潜金散 qián jīn sàn 120 @@ -625614,6 +625618,7 @@ sort: by_weight 说付费 shuō fù fèi 76 说服了 shuō fú le 156 说服力 shuō fú lì 310 +说服人 shuō fú rén 169 说服务 shuō fú wù 62 说负责 shuō fù zé 71 说服者 shuō fú zhě 98 @@ -647305,7 +647310,6 @@ sort: by_weight 他深得 tā shēn de 332 他身法 tā shēn fǎ 142 他身份 tā shēn fèn 133 -他身分 tā shēn fèn 118 他身负 tā shēn fù 478 他深感 tā shēn gǎn 87 他身高 tā shēn gāo 101 @@ -668230,6 +668234,7 @@ sort: by_weight 挺美的 tǐng měi de 234 挺美好 tǐng měi hǎo 142 挺没劲 tǐng méi jìn 116 +挺没救 tǐng méi jiù 306 挺美丽 tǐng měi lì 96 听没听 tīng méi tīng 144 停没有 tíng méi yǒu 89 @@ -815838,6 +815843,8 @@ sort: by_weight 这软件 zhè ruǎn jiàn 185 这仨人 zhè sā rén 141 柘赛湖 zhè sài hú 54 +这三步 zhè sān bù 596 +这三部 zhè sān bù 482 遮三丑 zhē sān chǒu 200 这三大 zhè sān dà 268 这三对 zhè sān duì 137 @@ -935961,7 +935968,6 @@ sort: by_weight 代表日本 dài biǎo rì běn 44 代表啥子 dài biǎo shá zi 1 代表身份 dài biǎo shēn fèn 61 -代表身分 dài biǎo shēn fèn 7 代表什么 dài biǎo shén me 66 代表市委 dài biǎo shì wěi 28 代表台湾 dài biǎo tái wān 100 @@ -1037991,7 +1037997,6 @@ sort: by_weight 翰墨丹青 hàn mò dān qīng 27 汉默丁格 hàn mò dīng gé 13 汉谟拉比 hàn mó lā bǐ 28 -汉莫拉比 hàn mò lā bǐ 14 翰墨留香 hàn mò liú xiāng 5 翰墨留韵 hàn mò liú yùn 4 翰墨凝香 hàn mò níng xiāng 4 @@ -1280116,7 +1280121,6 @@ sort: by_weight 身份卑微 shēn fèn bēi wēi 32 身份标识 shēn fèn biāo shí 45 身份不明 shēn fèn bù míng 47 -身分不明 shēn fèn bù míng 15 身份重启 shēn fèn chóng qǐ 6 身份登记 shēn fèn dēng jì 37 身份等级 shēn fèn děng jí 30 @@ -1280141,10 +1280145,10 @@ sort: by_weight 身份显赫 shēn fèn xiǎn hè 29 身份象征 shēn fèn xiàng zhēng 62 身份信息 shēn fèn xìn xī 47 -身分掩护 shēn fèn yǎn hù 6 +身份掩护 shēn fèn yǎn hù 6 身份验证 shēn fèn yàn zhèng 68 身份优势 shēn fèn yōu shì 4 -身分障碍 shēn fèn zhàng ài 17 +身份障碍 shēn fèn zhàng ài 17 身份真实 shēn fèn zhēn shí 23 身份证啊 shēn fèn zhèng a 32 身份证绑 shēn fèn zhèng bǎng 7 @@ -1293275,6 +1293279,7 @@ sort: by_weight 世纪动画 shì jì dòng huà 8 世纪东路 shì jì dōng lù 11 世纪东山 shì jì dōng shān 7 +时机对不 shí jī duì bu 36 世纪对决 shì jì duì jué 27 是几多啊 shì jǐ duō a 1 是几多钱 shì jǐ duō qián 5 @@ -1312148,7 +1312153,6 @@ sort: by_weight 双重人格 shuāng chóng rén gé 79 双重伤害 shuāng chóng shāng hài 34 双重身份 shuāng chóng shēn fèn 51 -双重身分 shuāng chóng shēn fèn 29 双重识别 shuāng chóng shí bié 10 双重时间 shuāng chóng shí jiān 6 双重束缚 shuāng chóng shù fù 22 @@ -1476128,6 +1476132,7 @@ sort: by_weight 有啥事没 yǒu shá shì méi 12 有啥说啥 yǒu shá shuō shá 41 有啥问题 yǒu shá wèn tí 79 +有啥遗漏 yǒu shá yí lòu 29 有啥意思 yǒu shá yì si 51 有啥影响 yǒu shá yǐng xiǎng 44 有啥用么 yǒu shá yòng me 7 diff --git a/lua/super_filter.lua b/lua/super_filter.lua index 049763b..b8874be 100644 --- a/lua/super_filter.lua +++ b/lua/super_filter.lua @@ -552,7 +552,88 @@ local function init_charset_filter(env, cfg) -- charsetblacklist: 黑名单 load_charset_list("charsetblacklist", env.charset_block) end +-- ======================================================= +-- 基于英文模式Preedit的智能分段空格 +-- ======================================================= +local function restore_sentence_spacing(cand) + local guide = cand.preedit or "" + -- 如果 Preedit 没空格,说明没分段,直接返回 + if not string.find(guide, " ") then return cand end + local text = cand.text + local text_len = #text + local parts = {} + local p = 1 -- 全局扫描指针 + -- 辅助:取纯字母小写指纹 + local function pure(s) return string.gsub(s, "[^a-zA-Z]", ""):lower() end + local function find_target_in_text(start_pos, target_fp) + -- 剪枝:如果剩下的长度比 target 还短,肯定没了 + if (text_len - start_pos + 1) < #target_fp then return nil, nil end + -- 从 start_pos 开始,向后逐字尝试 + for i = start_pos, text_len do + -- 首字母必须匹配,才值得进去做全词扫描 + -- 比如 target="apple",只有遇到 'a'/'A' 才进去看 + local char_i = string.sub(text, i, i) + local first_char_fp = string.lower(char_i) + if first_char_fp == string.sub(target_fp, 1, 1) then + -- 潜入匹配:尝试从位置 i 开始凑齐 target + local scan_p = i + local letters_acc = "" + while scan_p <= text_len do + local char = string.sub(text, scan_p, scan_p) + -- 只收集字母 + if string.find(char, "[a-zA-Z]") then + letters_acc = letters_acc .. string.lower(char) + end + if letters_acc == target_fp then + -- 找到了!返回 (起点, 终点) + return i, scan_p + end + -- 剪枝:如果凑出来的字母已经比目标不一样或更长,说明不是这个 + -- 比如 target="app", 凑出了 "apx" -> 失败,跳出 while,继续外层 for + if #letters_acc > #target_fp then break end + if string.sub(letters_acc, 1, #letters_acc) ~= string.sub(target_fp, 1, #letters_acc) then break end + scan_p = scan_p + 1 + end + end + end + return nil, nil + end + -- 遍历 Preedit 的每一段 + for seg in string.gmatch(guide, "%S+") do + local target = pure(seg) + if #target > 0 then + -- 在当前指针 p 往后无限寻找 + local match_start, match_end = find_target_in_text(p, target) + if match_start then + -- 隔离病灶(中间跳过不匹配的) + if match_start > p then + local lesion = string.sub(text, p, match_start - 1) + table.insert(parts, lesion) + end + -- 存入正确单词 + local valid_word = string.sub(text, match_start, match_end) + table.insert(parts, valid_word) + -- 更新指针 + p = match_end + 1 + else + -- 没找到:说明这个 preedit 词完全消失了(比如 preedit 有 5 个词,candidate 只有 4 个) + -- 策略:忽略这个 guide,继续用下一个 guide 找 + end + end + end + -- 尾部处理 + if p <= text_len then + local tail = string.sub(text, p) + if #parts > 0 then table.insert(parts, tail) + else table.insert(parts, tail) end + end + -- 重组 + local new_text = table.concat(parts, " ") + local nc = Candidate(cand.type, cand.start, cand._end, new_text, cand.comment) + nc.preedit = cand.preedit + return nc +end -- ========= 生命周期 ========= function M.init(env) local cfg = env.engine and env.engine.schema and env.engine.schema.config or nil @@ -650,37 +731,43 @@ local function emit_with_pipeline(cand, ctxs) local env = ctxs.env - -- ① 字符集过滤:只有在 charset_strict = true 时才启用 + -- 1. 字符集过滤:只有在 charset_strict = true 时才启用 if ctxs.charset_strict and cand.text and cand.text ~= "" then if not in_charset(env, cand.text) then return end end - - -- ② 三态语言模式 + -- 2. 准备变量 local is_en = ctxs.is_english and ctxs.is_english(cand) or false + local BAGUA_SYMBOL = "\226\152\175" + local is_bagua_sentence = (fast_type(cand) == "sentence") and (cand.comment and string.find(cand.comment, BAGUA_SYMBOL)) - if ctxs.en_only and (not is_en) then - return - end + -- 3. 三态语言过滤 + if ctxs.zh_only and is_en then return end + if ctxs.en_only and (not is_en) then return end - if ctxs.zh_only and is_en then - return - end - - -- **③ 若需抑制句子候选:删掉所有 type 为 sentence 的候选(除了首候选本身不会被标记)** - if ctxs.drop_sentence_after_completion then - if fast_type(cand) == "sentence" then - return + -- 4. 八卦图处理 + if ctxs.en_only then + -- 英文模式:如果是八卦图,用 Preedit 还原空格 + if is_bagua_sentence then + cand = restore_sentence_spacing(cand) end + elseif (not ctxs.zh_only) then + -- 混合模式:隐藏 + if is_bagua_sentence then return end end - -- ④ 镜像抑制 + -- 5. 抑制句子 + if (not ctxs.en_only) and ctxs.drop_sentence_after_completion then + if fast_type(cand) == "sentence" then return end + end + + -- 6 镜像抑制 if ctxs.suppress_mirror and ctxs.suppress_set and ctxs.suppress_set[cand.text] then return end - -- ⑤ 格式化 + 大写 + span 对齐 + -- 7 格式化 + 大写 + span 对齐 cand = format_and_autocap(cand, ctxs.code_ctx) cand = ctxs.unify_tail_span(cand) yield(cand) diff --git a/wanxiang.schema.yaml b/wanxiang.schema.yaml index bbb339d..49804b6 100644 --- a/wanxiang.schema.yaml +++ b/wanxiang.schema.yaml @@ -97,8 +97,8 @@ engine: - reverse_lookup_filter@radical_reverse_lookup #部件拆字滤镜,放在super_comment前面,进一步被超级注释处理以获得拼音编码的提示 - lua_filter@*auto_phrase #comment前,无感造词,关闭调频的时候将汉字写入次翻译器,当没有英文候选的时候追加\上屏可完成英文造词 - lua_filter@*super_lookup #comment前,字词输入中反查辅助筛选 + - lua_filter@*super_filter #comment前,功能太多详见Lua文件 - lua_filter@*super_comment_preedit #OpenCC前,超级注释模块、超级preedit,支持错词提示、辅助码显示,部件组字读音注释,有声调、无声调全拼编码的转换,支持个性化配置和关闭相应的功能,详情搜索super_comment_preedit进行详细配置 - - lua_filter@*super_filter #功能太多详见Lua文件 - simplifier@emoji #Emoji滤镜 - simplifier@s2t #简繁切换通繁 - simplifier@s2tw #简繁切换台繁 @@ -356,7 +356,6 @@ translator: # user_dict: zrm.userdb # 用户词典的文件名称 # db_class: tabledb #开启后就不会产生wanxiang.userdb这样的文件夹,会直接输出文本wanxiang.txt同时无法使用同步能力,可设 tabledb〔文本〕或 userdb〔二进制〕 enable_user_dict: true # 是否开启自动调频,即开启用户词典 -# enable_encoder: true #是否开启自动造词 # enable_sentence: false #是否开启自动造句 # enable_correction: false #是否开启自动纠错 # encode_commit_history: true # 预留历史上屏自动编码成词 @@ -396,11 +395,8 @@ wanxiang_mixedcode: dictionary: wanxiang_mixedcode user_dict: en enable_completion: true - enable_sentence: false + enable_sentence: true initial_quality: 2 - comment_format: - - xform/^.+$// - # Emoji emoji: @@ -579,9 +575,8 @@ key_binder: #通过快捷键Control+g开启字符集过滤 - { when: has_menu, accept: "Control+g", toggle: charset_filter } - { when: composing, accept: "Control+g", toggle: charset_filter } -#通过快捷键Control+q切换中文、英文、混合模式 - - { when: has_menu, accept: "Control+q", toggle: zh_only } - - { when: composing, accept: "Control+q", toggle: zh_only } +#通过快捷键Shift+space开启输入模式切换 + - { when: always, accept: "Shift+space", toggle: zh_only } # 使用 tab 在不同音节之间跳转 - { when: has_menu, accept: "Tab", send: "Control+Right" } - { when: composing, accept: "Tab", send: "Control+Right" } diff --git a/wanxiang_t9.schema.yaml b/wanxiang_t9.schema.yaml index fb7c6a3..3908ae9 100644 --- a/wanxiang_t9.schema.yaml +++ b/wanxiang_t9.schema.yaml @@ -77,16 +77,16 @@ engine: - table_translator@wanxiang_mixedcode #中英等混合词汇表导入 - table_translator@wanxiang_reverse #挂接部件组字和笔画反查 filters: - - lua_filter@*super_sequence*F #手动排序,高亮候选 ctrl+j左移动 ctrl+k 右移动 ctrl+0 移除位移 - reverse_lookup_filter@radical_reverse_lookup #部件拆字滤镜,放在super_comment前面,进一步被超级注释处理以获得拼音编码的提示 - lua_filter@*super_lookup #字词输入中反查辅助筛选 + - lua_filter@*super_filter #功能太多详见Lua文件 - lua_filter@*super_comment_preedit #超级注释模块、超级preedit,支持错词提示、辅助码显示,部件组字读音注释,有声调、无声调全拼编码的转换,支持个性化配置和关闭相应的功能,详情搜索super_comment_preedit进行详细配置 - simplifier@emoji #Emoji滤镜 - simplifier@s2t #简繁切换通繁 - simplifier@s2tw #简繁切换台繁 - simplifier@s2hk #简繁切换港繁 - simplifier@chinese_english #中英翻译滤镜 - - lua_filter@*super_filter #功能太多详见Lua文件 + - lua_filter@*super_sequence*F #手动排序,高亮候选 ctrl+j左移动 ctrl+k 右移动 ctrl+0 移除位移 - uniquifier # 去重 super_comment: # 超级注释模块,子项配置 true 开启,false 关闭