rime_config/lua/codeLengthLimit_processor.lua
2024-08-26 21:19:51 +08:00

30 lines
702 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local M = {}
local kRejected = 0 -- 输入法拒绝处理
local kAccepted = 1 -- 输入法接受处理并由本processor处理
local kNoop = 2 -- 交由输入法下一个processor判断是否处理
function M.init(env)
local config = env.engine.schema.config
env.name_space = env.name_space:gsub('^*', '')
end
function M.func(key, env)
local ctx = env.engine.context
local config = env.engine.schema.config
-- 限制
local length_limit = config:get_string(env.name_space)
if(length_limit~=nil) then
if(string.len(ctx.input) > tonumber(length_limit)) then
-- ctx:clear()
ctx:pop_input(1)
return kAccepted
end
end
-- 放行
return kNoop
end
return M