Windows 小狼豪,按下“m”,在第8个候选显示为“时间”,怎么用lua实现?

我知道使用lua可以设置时间,但是怎么把时间定在候选8这个位置?这能固定到候选第8位吗?如果要实现需要用到哪个参数?(我略懂编程,如果能实现,给我看个几个代码就够了)

不仅仅是第8位,第5到第9位我都想自定义设置。所以不能采用custom_phrase.txt或者词库写入,因为我要用来候选9,打开各种程序,所以预先写进词库行不通,要用lua解决。

1 个赞

AI是个好东西。

1 个赞

在输入方案里好像可以设置出现在第几位呢

我就是问了ai,ai给不出答案才发帖的,你贴的ai回复其实就是ai在乱编。

昨晚我看了不少例子,自己搞出来了。

local function filter(input, env)
    local input_text = env.engine.context.input
    
    if input_text == "m" then
        local i = 0
        for cand in input:iter() do
            i=i+1
            yield(cand)
            if i == 8 then
                yield(Candidate("error", 0, #input_text, "时间", "注释"))
            end
        end
    else
        for cand in input:iter() do
            yield(cand)
        end
    end
end
return filter

在文件夹lua下创建文件test_filter.lua,放入上面代码。
/storage/emulated/0/rime/lua/test_filter.lua

之后在方案的 filters:的最后加入 - lua_filter@*test_filter,最好在最后一行加入,避免被其他filter改了顺序

  filters:
    - lua_filter@*test_filter

重新部署后生效

1 个赞