From 555ece61fcbb764e6f0eff27a0c044628124d740 Mon Sep 17 00:00:00 2001 From: amzxyz Date: Fri, 5 Dec 2025 13:35:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Ealt+=E5=AD=97?= =?UTF-8?q?=E6=AF=8D=E8=B7=B3=E8=BD=AC=E5=AF=B9=E5=BA=94=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E5=90=8E=E9=9D=A2=EF=BC=8C=E4=BD=86asdt=E7=AD=89=E5=AD=97?= =?UTF-8?q?=E6=AF=8D=E6=9C=89=E8=A2=ABrime=E5=B1=8F=E8=94=BD=EF=BC=8C?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E5=BF=AB=E6=8D=B7=E9=94=AE=E6=9C=89=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=A8=8B=E5=BA=A6=E5=8D=A0=E7=94=A8=EF=BC=8C=E5=85=88?= =?UTF-8?q?=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom/wanxiang_pro.schema.yaml | 1 + lua/alt_jump.lua | 90 +++++++++++++++++++++++++++++++++ wanxiang.schema.yaml | 1 + 3 files changed, 92 insertions(+) create mode 100644 lua/alt_jump.lua diff --git a/custom/wanxiang_pro.schema.yaml b/custom/wanxiang_pro.schema.yaml index 96635fe..781fb86 100644 --- a/custom/wanxiang_pro.schema.yaml +++ b/custom/wanxiang_pro.schema.yaml @@ -68,6 +68,7 @@ engine: - recognizer #与 matcher 搭配,处理符合特定规则的输入码,如网址、反查等 tags - key_binder #在特定条件下将按键绑定到其他按键,如重定义逗号、句号为候选翻页、开关快捷键等 - lua_processor@*key_binder #绑定按键扩展能力,支持正则扩展将按键生效情景更加细化 + - lua_processor@*alt_jump #通过alt+字母进行跳转输入编码对应的字母,非完全版,asdt等按键被rime屏蔽了 - speller #拼写处理器,接受字符按键,编辑输入 - punctuator #符号处理器,将单个字符按键直接映射为标点符号或文字 - selector #选字处理器,处理数字选字键〔可以换成别的哦〕、上、下候选定位、换页 diff --git a/lua/alt_jump.lua b/lua/alt_jump.lua new file mode 100644 index 0000000..d375d35 --- /dev/null +++ b/lua/alt_jump.lua @@ -0,0 +1,90 @@ +-- amzxyz@https://github.com/amzxyz/rime_wanxiang +-- lua/alt_jump.lua +-- Alt + 字母:把输入法光标跳到对应字母后面,系统占用了asdt等几个按键不起作用,暂时不,没办法 +-- 多个相同字母时轮询跳转(i > caret) + +local wanxiang = require("wanxiang") +local R = wanxiang.RIME_PROCESS_RESULTS -- 简化引用(可选) + +---------------------------------------------------------------------- +-- 移动光标到“下一个 ch 后面”,并支持轮询 +---------------------------------------------------------------------- +local function move_to_next_char(context, ch) + local input = context.input + if not input or input == "" then + return false + end + + local len = #input + local caret = context.caret_pos + if type(caret) ~= "number" then + caret = 0 + end + + local first_pos = nil + local next_pos = nil + + for i = 1, len do + if input:sub(i, i) == ch then + if not first_pos then + first_pos = i + end + -- ⚠️ 核心:必须是 i > caret,而不是 i >= caret + if (i > caret) and (not next_pos) then + next_pos = i + end + end + end + + if not first_pos then + return false + end + + -- 若后面没有相同字母 → 回圈到第一个 + local target = next_pos or first_pos + + context.caret_pos = target + context:refresh_non_confirmed_composition() + return true +end + +---------------------------------------------------------------------- +-- 主处理器:拦截 Alt + 字母 +---------------------------------------------------------------------- +local function processor(key, env) + local context = env.engine.context + + if key:release() then + return R.kNoop + end + + if not key:alt() then + return R.kNoop + end + + if not context:is_composing() then + return R.kNoop + end + + local code = key.keycode + if not code then + return R.kNoop + end + + local ch + if code >= string.byte("a") and code <= string.byte("z") then + ch = string.char(code) + elseif code >= string.byte("A") and code <= string.byte("Z") then + ch = string.char(code + 32) + else + return R.kNoop + end + + if move_to_next_char(context, ch) then + return R.kAccepted + else + return R.kNoop + end +end + +return processor diff --git a/wanxiang.schema.yaml b/wanxiang.schema.yaml index 58d36d3..7c08239 100644 --- a/wanxiang.schema.yaml +++ b/wanxiang.schema.yaml @@ -64,6 +64,7 @@ engine: - recognizer #与 matcher 搭配,处理符合特定规则的输入码,如网址、反查等 tags - key_binder #在特定条件下将按键绑定到其他按键,如重定义逗号、句号为候选翻页、开关快捷键等 - lua_processor@*key_binder #绑定按键扩展能力,支持正则扩展将按键生效情景更加细化 + - lua_processor@*alt_jump #通过alt+字母进行跳转输入编码对应的字母,非完全版,asdt等按键被rime屏蔽了 - speller #拼写处理器,接受字符按键,编辑输入 - punctuator #符号处理器,将单个字符按键直接映射为标点符号或文字 - selector #选字处理器,处理数字选字键〔可以换成别的哦〕、上、下候选定位、换页