Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何实现以VV开头的字符串(其中可能有a-zA-Z0-9),然后去掉VV这两个字母直接上屏? #1142

Closed
netvolcano opened this issue Jan 11, 2025 · 4 comments

Comments

@netvolcano
Copy link

摘要

以VV开头的字符串(其中可能有a-zA-Z0-9),然后去掉VV这两个字母直接上屏

输入方案

小鹤双拼 double_pinyin_flypy

相关应用

weasel 0.16.3

系统信息

Win11

详细说明

有时候需要输入一些字母与数字混杂的字符串,又不想切换输入法,就想在字符串前面加上VV开头,希望能够在最后按下回车后,去掉VV开头、把剩余的其他字符串直接上屏,请问如何实现?如何打一个补丁?

自定义配置

No response

@netvolcano
Copy link
Author

我自己写了lua,一直没有调试成功,代码如下:

-- 方案文件配置,
-- recognizer/patterns/vv_prefix_text: "^VV([0-9]|10|[A-Za-z]+)$"
local rime = require "rime"

-- 初始化符号输入的状态
local function init(env)
    -- 读取 RIME 配置文件中的引导符号模式
    local config = env.engine.schema.config

    local vv_prefix_text = config:get_string("recognizer/patterns/vv_prefix_text")

    -- 生成单引导符和双引导符模式
    env.vv_prefix_pattern = vv_prefix_text
    -- rime.log("init" .. vv_prefix_text)

end

-- 处理符号和文本的重复上屏逻辑
local function processor(key_event, env)
    local engine  = env.engine
    local context = engine.context
    local input   = context.input  -- 当前输入的字符串

    -- 1. 检查是否输入的编码为双引导符 ;;,用于汉字或字母重复上屏
    -- local vv_prefix_pattern = "^VV([0-9]|10|[A-Za-z]+)$"
    if key_event.keycode == 0xff0d and key_event:release() then
        if string.match(input, env.vv_prefix_pattern) then
            rime.log("enter VV prefix" .. input)
            local remaining_input = string.sub(input, 3)
            engine:commit_text(remaining_input)  -- 上屏上次的汉字或文本
            context:clear()  -- 清空输入
            return 1  -- 捕获事件,处理完成
        end
    end
    -- rime.log("enter VV prefix")

    return 2  -- 未处理事件,继续传播
end

-- 导出到 RIME
return { init = init, func = processor }

能看看你的代码吗?或者帮我看看问题在什么地方?我还不会使用debug功能来寻找问题所在

@dyfllll
Copy link

dyfllll commented Jan 13, 2025

如果是输入字母与数字混杂的字符串,我这实现了只要输入小键盘数字直接将输入的内容上屏,一般数字键还是选择,应该是你想要的吧
同样不用切换输入法,而且也省的打vv了,不过必须要有小键盘
https://github.com/dyfllll/rime-ice/blob/main/lua/kp_input.lua

@netvolcano
Copy link
Author

如何使用?把这个东西放在主scheme的什么位置?

@dyfllll
Copy link

dyfllll commented Jan 13, 2025

建一个rime_ice.custom.yaml
加入这个就行
patch:
engine/processors/@before 0: lua_processor@*kp_input

https://github.com/dyfllll/rime-ice/blob/main/rime_ice.custom.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants