From 789e3776de2a5487751678a78214ca92b97010d2 Mon Sep 17 00:00:00 2001 From: amzxyz Date: Mon, 19 Jan 2026 22:24:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=B1=E4=BA=8E=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E7=94=B1=E6=BB=A4=E9=95=9C=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E7=9A=84=E4=B8=AD=E8=8B=B1=E6=96=87=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=8E=BB=E6=8E=89=EF=BC=8C=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E5=88=87=E6=8D=A2=E6=96=B9=E6=A1=88=E6=9D=A5?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=B8=AD=E8=8B=B1=E6=96=87=E5=88=87=E6=8D=A2?= =?UTF-8?q?=EF=BC=8C=E5=BF=AB=E6=8D=B7=E9=94=AE=E8=BF=98=E6=98=AFshift+spa?= =?UTF-8?q?ce,=E4=BD=86=E4=B8=8D=E5=86=8D=E6=9C=89=E4=BB=85=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E7=9A=84=E6=A8=A1=E5=BC=8F=EF=BC=8C=E6=9C=89=E9=9C=80?= =?UTF-8?q?=E6=B1=82=E7=9A=84=E7=94=A8=E6=88=B7=E5=8F=AF=E4=BB=A5=E9=80=9A?= =?UTF-8?q?=E8=BF=87patch=E5=8E=BB=E6=8E=89=E8=8B=B1=E6=96=87=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=8C=82=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom/wanxiang_pro.schema.yaml | 8 ++-- default.yaml | 2 +- lua/super_filter.lua | 83 +++++++++++---------------------- wanxiang.schema.yaml | 8 ++-- wanxiang_algebra.yaml | 10 ++-- wanxiang_english.schema.yaml | 5 +- 6 files changed, 48 insertions(+), 68 deletions(-) diff --git a/custom/wanxiang_pro.schema.yaml b/custom/wanxiang_pro.schema.yaml index 6904a39..d83d9c6 100644 --- a/custom/wanxiang_pro.schema.yaml +++ b/custom/wanxiang_pro.schema.yaml @@ -49,8 +49,7 @@ switches: states: [ 简体, 通繁, 港繁, 臺繁 ] - name: char_priority #多体现在编码重合但候选有单字或者多字的情况`引导的辅码查词时是否单字优先,全拼常见,类似于特定编码情况下、反查状态下的调序能力。归属:super_lookup.lua states: [词组先, 单字先] - - options: [ mixed, zh_only, en_only ] - states: [ 混合输入, 仅中文, 仅英文 ] + # 输入引擎 engine: @@ -499,6 +498,7 @@ wanxiang_english: #支持设置延时销毁加空格状态,单位秒,0不超时,大于0为超时时间,极大的保证了连续输入的体验。 english_spacing: smart spacing_timeout: 5 + wanxiang_mixedcode: dictionary: wanxiang_mixedcode db_class: stabledb @@ -621,7 +621,9 @@ key_binder: - { when: has_menu, accept: "Control+g", toggle: charset_filter } - { when: composing, accept: "Control+g", toggle: charset_filter } #通过快捷键Shift+space开启输入模式切换 - - { when: always, accept: "Shift+space", toggle: zh_only } + #- { when: always, accept: Shift+space, select: wanxiang } #直接跳转指定方案 + #- { when: always, accept: Shift+space, select: wanxiang_pro } #直接跳转指定方案 + - { when: always, accept: Shift+space, select: .next } #下一个方案 # 使用 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 e8fbf47..3f046a7 100644 --- a/default.yaml +++ b/default.yaml @@ -9,7 +9,7 @@ config_version: 'LTS' # 方案列表 schema_list: - schema: wanxiang - + - schema: wanxiang_english # - schema: wanxiang_t9 # 菜单 menu: diff --git a/lua/super_filter.lua b/lua/super_filter.lua index 6090d68..22f61f7 100644 --- a/lua/super_filter.lua +++ b/lua/super_filter.lua @@ -14,12 +14,8 @@ -- 镜像: -- - schema: paired_symbols/mirror (bool,默认 true) -- - 包裹后可抑制"包裹前文本/包裹后文本"再次出现在后续候选里 --- 功能 D:三态语言模式(通过 options 控制,仅在输出层过滤,不改变内部逻辑) --- - ctx:get_option("en_only") == true → 仅英文:只保留英文候选 --- - ctx:get_option("zh_only") == true → 仅中文:丢弃英文候选 --- - 两者都 false → 混合模式:中英都输出 --- 功能E 字符集过滤,默认8105+𰻝𰻝,可以在方案中定义黑白名单来实现用户自己的范围微调addlist: []和blacklist: [𰻝, 𰻞] --- 功能F 由于在混输场景中输入comment commit等等之类的英文时候,由于直接辅助码的派生能力,会将三个好不想干的单字组合在一起,这会造成不好的体验 +-- 功能D 字符集过滤,默认8105+𰻝𰻝,可以在方案中定义黑白名单来实现用户自己的范围微调addlist: []和blacklist: [𰻝, 𰻞] +-- 功能E 由于在混输场景中输入comment commit等等之类的英文时候,由于直接辅助码的派生能力,会将三个好不想干的单字组合在一起,这会造成不好的体验 -- 因此在首选已经是英文的时候,且type=completion且大于等于4个字符,这个时候后面如果有type=sentence的派生词则直接干掉,这个还要依赖,表翻译器 -- 权重设置与主翻译器不可相差太大 @@ -57,7 +53,6 @@ local function has_english_token_fast(s) end return false end - -- 纯ASCII判定 local function is_english_candidate(cand) local txt = cand and cand.text @@ -72,8 +67,6 @@ local function is_english_candidate(cand) return true end --- ================= 文本格式化 ================= - local escape_map = { ["\\n"] = "\n", -- 换行 ["\\r"] = "\r", -- 回车 @@ -283,8 +276,6 @@ local function precompile_wrap_parts(wrap_map, delimiter) return parts end --- ================= 字符集过滤核心 ================= - -- 检查交集 local function check_intersection(db_attr, config_base_set) if not db_attr or db_attr == "" then return false end @@ -461,13 +452,6 @@ local function in_charset(env, ctx, text) return codepoint_in_charset(env, ctx, target_cp, char) end -local function is_reverse_lookup_segment(env) - if not env or not env.engine or not env.engine.context then return false end - local comp = env.engine.context.composition - if not comp or comp:empty() then return false end - local seg = comp:back() - return seg and (seg:has_tag("wanxiang_reverse") or seg:has_tag("add_user_dict") or seg:has_tag("punct")) -end -- 生命周期 function M.init(env) @@ -513,19 +497,24 @@ function M.init(env) end -- 字符集过滤 init_charset_filter(env, cfg) + local schema_id = env.engine.schema.schema_id + env.enable_taichi_filter = (schema_id == "wanxiang" or schema_id == "wanxiang_pro") end function M.fini(env) + env.charset_db = nil + env.db_memo = nil + env.filters = nil + env.wrap_map = nil + env.wrap_parts = nil end -- 统一产出通道 -- ctxs: -- charset : 字符集过滤 --- suppress_set : { [text] = true } 阻止镜像文本 +-- suppress_set : { [text] = true } 阻止镜像文本 -- suppress_mirror : bool -- code_ctx : 编码上下文 -- unify_tail_span : 尾部 span 对齐函数 --- en_only / zh_only: 三态语言模式 --- is_english : 函数(cand) → bool local function emit_with_pipeline(cand, ctxs) if not cand then return end local env = ctxs.env @@ -536,35 +525,28 @@ local function emit_with_pipeline(cand, ctxs) return end end - - -- ② 三态语言模式 - local is_en = ctxs.is_english and ctxs.is_english(cand) or false - if (not ctxs.en_only) and is_en then - if cand.comment and string.find(cand.comment, "\226\152\175") then - return -- 包含☯的英文句子直接丢弃,不输出 + -- 如果是英文句子,且注释包含 ☯ (\226\152\175),则丢弃 + if ctxs.enable_taichi_filter then + -- 只有在 wanxiang 或 wanxiang_pro 方案下才执行此过滤 + if cand.text and has_english_token_fast(cand.text) then + if cand.comment and find(cand.comment, "\226\152\175") then + return + end end end - if ctxs.en_only and (not is_en) then - return - end - - if ctxs.zh_only and is_en then - return - end - - -- **③ 若需抑制句子候选:删掉所有 type 为 sentence 的候选(除了首候选本身不会被标记)** + -- ② 若需抑制句子候选:删掉所有 type 为 sentence 的候选(除了首候选本身不会被标记)** if ctxs.drop_sentence_after_completion then if fast_type(cand) == "sentence" then return end end - -- ④ 镜像抑制 + -- ③ 镜像抑制 if ctxs.suppress_mirror and ctxs.suppress_set and ctxs.suppress_set[cand.text] then return end - -- ⑤ 格式化 + 大写 + span 对齐 + -- ④ 格式化 + 大写 + span 对齐 cand = format_and_autocap(cand) cand = ctxs.unify_tail_span(cand) yield(cand) @@ -575,15 +557,13 @@ function M.func(input, env) local code = ctx and (ctx.input or "") or "" local comp = ctx and ctx.composition or nil + local is_functional = false + if ctx and wanxiang and wanxiang.is_function_mode_active then + is_functional = wanxiang.is_function_mode_active(ctx) + end - local in_reverse_seg = is_reverse_lookup_segment(env) - - -- 本次是否启用 charset 过滤 - -- 逻辑改为:只要有规则,且不在反查模式下,就激活检查。 - -- 具体到底显示还是隐藏,由 codepoint_in_charset 内部根据开关状态决定。 - local charset_active = (env.filters and #env.filters > 0) - and (not in_reverse_seg) - + local charset_active = (env.filters and #env.filters > 0) + and (not is_functional) -- 状态清理 if not code or code == "" then env.cache, env.locked = nil, false @@ -642,12 +622,6 @@ function M.func(input, env) pure_code_lc = pure_code_lc, } - local en_only, zh_only = false, false - if ctx then - en_only = ctx:get_option("en_only") or false - zh_only = ctx:get_option("zh_only") or false - end - local function unify_tail_span(c) if fully_consumed and wrap_key and last_seg and c and c._end ~= last_seg._end then local nc = Candidate(c.type, c.start, last_seg._end, c.text, c.comment) @@ -664,10 +638,9 @@ function M.func(input, env) suppress_mirror = env.suppress_mirror, code_ctx = code_ctx, unify_tail_span = unify_tail_span, - en_only = en_only, - zh_only = zh_only, - is_english = is_english_candidate, charset_active = charset_active, + is_english = is_english_candidate, + enable_taichi_filter = env.enable_taichi_filter, drop_sentence_after_completion = false, } diff --git a/wanxiang.schema.yaml b/wanxiang.schema.yaml index 3bbfc43..785e6c7 100644 --- a/wanxiang.schema.yaml +++ b/wanxiang.schema.yaml @@ -44,8 +44,7 @@ switches: reset: 0 - name: char_priority #多体现在编码重合但候选有单字或者多字的情况`引导的辅码查词时是否单字优先,全拼常见,类似于特定编码情况下、反查状态下的调序能力。归属:super_lookup.lua states: [词组先, 单字先] - - options: [ mixed, zh_only, en_only ] - states: [ 混合输入, 仅中文, 仅英文 ] + # 输入引擎 engine: @@ -496,6 +495,7 @@ wanxiang_english: #支持设置延时销毁加空格状态,单位秒,0不超时,大于0为超时时间,极大的保证了连续输入的体验。 english_spacing: smart spacing_timeout: 5 + wanxiang_mixedcode: dictionary: wanxiang_mixedcode db_class: stabledb @@ -613,7 +613,9 @@ key_binder: - { when: has_menu, accept: "Control+g", toggle: charset_filter } - { when: composing, accept: "Control+g", toggle: charset_filter } #通过快捷键Shift+space开启输入模式切换 - - { when: always, accept: "Shift+space", toggle: zh_only } + #- { when: always, accept: Shift+space, select: wanxiang } #直接跳转指定方案 + #- { when: always, accept: Shift+space, select: wanxiang_pro } #直接跳转指定方案 + - { when: always, accept: Shift+space, select: .next } #下一个方案 # 使用 tab 在不同音节之间跳转 - { when: has_menu, accept: "Tab", send: "Control+Right" } - { when: composing, accept: "Tab", send: "Control+Right" } diff --git a/wanxiang_algebra.yaml b/wanxiang_algebra.yaml index c882ae8..8733eec 100644 --- a/wanxiang_algebra.yaml +++ b/wanxiang_algebra.yaml @@ -40,16 +40,16 @@ base: - derive/^ng(\d)$/eng$1/ - xform/^n(\d)/en$1/ - xform/^m(\d)(;.*)/me$1$2/ - - abbrev/(.+)(\d)/\U$1/ - - abbrev/^([zcs]h).+$/\U$1/ #zh ch sh作为整体 - - abbrev/^([zcs]h).+(\d)$/\U$1$2/ #zh ch sh作为整体 - - derive/([nl])ve(\d)/$1UE$2/ #让üè兼容ue + - abbrev/^([zcs]h).+$/$1/ #zh ch sh作为整体 + - abbrev/^([zcs]h).+(\d)$/$1$2/ #zh ch sh作为整体 + - derive/([nl])ve(\d)/$1ue$2/ #让üè兼容ue - derive/^([jqxy])v(\d)$/$1u$2/ - derive/^([jqxy])u(\d)$/$1v$2/ - abbrev/^([qwrtypsdfghjklzxcbnm]).+$/$1/ #不携带元音的声母派生出首字母简码来 - abbrev/^([qwrtypsdfghjklzxcbnm]).+(\d)$/$1$2/ #不携带元音的声母派生出首字母简码来+数字声调 - abbrev/^([aoe])([ioun])(\d)$/$1/ #携带两个字符的元音首字母派生出简码来 - abbrev/^([aoe])([ioun])(\d)$/$1$3/ #携带两个字符的元音首字母派生出简码来+数字声调 + - derive/(.+)(\d)/$1/ - derive/([zcs])h(a|e|i|u|ai|ei|an|en|ou|uo|ua|un|ui|uan|uai|uang|ang|eng|ong)$/h$1$2/ # hzi → zhi - derive/([zcs])h([aeiu])$/$1$2h/ # zih → zhi # ai @@ -113,7 +113,7 @@ base: # 其他 - derive/ong$/on/ # lon → long - derive/([tl])eng$/$1en/ # ten → teng - - xform/^(.*)$/\L$1/ + 自然码: diff --git a/wanxiang_english.schema.yaml b/wanxiang_english.schema.yaml index 8807169..2b1f500 100755 --- a/wanxiang_english.schema.yaml +++ b/wanxiang_english.schema.yaml @@ -52,7 +52,10 @@ translator: - xform/^~.+$// key_binder: import_preset: default - + bindings: + #- { when: always, accept: Shift+space, select: wanxiang } #直接跳转指定方案 + #- { when: always, accept: Shift+space, select: wanxiang_pro } #直接跳转指定方案 + - { when: always, accept: Shift+space, select: .next } #下一个方案 recognizer: import_preset: default