feat: 新增alt+字母跳转对应编码后面,但asdt等字母有被rime屏蔽,其他快捷键有不同程度占用,先发布

This commit is contained in:
amzxyz
2025-12-05 13:35:42 +08:00
parent afca1e28ba
commit 555ece61fc
3 changed files with 92 additions and 0 deletions

View File

@@ -68,6 +68,7 @@ engine:
- recognizer #与 matcher 搭配,处理符合特定规则的输入码,如网址、反查等 tags
- key_binder #在特定条件下将按键绑定到其他按键,如重定义逗号、句号为候选翻页、开关快捷键等
- lua_processor@*key_binder #绑定按键扩展能力,支持正则扩展将按键生效情景更加细化
- lua_processor@*alt_jump #通过alt+字母进行跳转输入编码对应的字母非完全版asdt等按键被rime屏蔽了
- speller #拼写处理器,接受字符按键,编辑输入
- punctuator #符号处理器,将单个字符按键直接映射为标点符号或文字
- selector #选字处理器,处理数字选字键〔可以换成别的哦〕、上、下候选定位、换页

90
lua/alt_jump.lua Normal file
View File

@@ -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

View File

@@ -64,6 +64,7 @@ engine:
- recognizer #与 matcher 搭配,处理符合特定规则的输入码,如网址、反查等 tags
- key_binder #在特定条件下将按键绑定到其他按键,如重定义逗号、句号为候选翻页、开关快捷键等
- lua_processor@*key_binder #绑定按键扩展能力,支持正则扩展将按键生效情景更加细化
- lua_processor@*alt_jump #通过alt+字母进行跳转输入编码对应的字母非完全版asdt等按键被rime屏蔽了
- speller #拼写处理器,接受字符按键,编辑输入
- punctuator #符号处理器,将单个字符按键直接映射为标点符号或文字
- selector #选字处理器,处理数字选字键〔可以换成别的哦〕、上、下候选定位、换页