feat(select_char): commit text directly if cand len < 2
This commit is contained in:
parent
e9a730f7f4
commit
b2596238ed
@ -1,15 +1,16 @@
|
|||||||
-- 以词定字
|
-- 以词定字
|
||||||
-- 原脚本 https://github.com/BlindingDark/rime-lua-select-character
|
-- 原脚本 https://github.com/BlindingDark/rime-lua-select-character
|
||||||
-- 删除了默认按键 [ ],和方括号翻页冲突,需要在 key_binder 下指定才能生效
|
-- 删除了默认按键 [ ],和方括号翻页冲突,需要在 key_binder 下指定才能生效
|
||||||
-- 20230526195910 不再错误地获取commit_text,而是直接获取get_selected_candidate().text。
|
-- 20230526195910 不再错误地获取commit_text,而是直接获取get_selected_candidate().text
|
||||||
-- 20240128141207 重写:将读取设置移动到 init 方法中;简化中文取字方法;预先判断候选存在与否,无候选取 input;
|
-- 20240128141207 重写:将读取设置移动到 init 方法中;简化中文取字方法;预先判断候选存在与否,无候选取 input
|
||||||
|
-- 20240508111725 当候选字数为 1 时,快捷键使该字上屏
|
||||||
|
|
||||||
local select = {}
|
local select = {}
|
||||||
|
|
||||||
function select.init(env)
|
function select.init(env)
|
||||||
local config = env.engine.schema.config
|
local config = env.engine.schema.config
|
||||||
select.first_key = config:get_string('key_binder/select_first_character')
|
env.first_key = config:get_string('key_binder/select_first_character')
|
||||||
select.last_key = config:get_string('key_binder/select_last_character')
|
env.last_key = config:get_string('key_binder/select_last_character')
|
||||||
end
|
end
|
||||||
|
|
||||||
function select.func(key, env)
|
function select.func(key, env)
|
||||||
@ -19,22 +20,28 @@ function select.func(key, env)
|
|||||||
if
|
if
|
||||||
not key:release()
|
not key:release()
|
||||||
and (context:is_composing() or context:has_menu())
|
and (context:is_composing() or context:has_menu())
|
||||||
and (select.first_key or select.last_key)
|
and (env.first_key or env.last_key)
|
||||||
then
|
then
|
||||||
local text = context.input
|
local text = context.input
|
||||||
if context:get_selected_candidate() then
|
if context:get_selected_candidate() then
|
||||||
text = context:get_selected_candidate().text
|
text = context:get_selected_candidate().text
|
||||||
end
|
end
|
||||||
if utf8.len(text) > 1 then
|
if utf8.len(text) > 1 then
|
||||||
if (key:repr() == select.first_key) then
|
if (key:repr() == env.first_key) then
|
||||||
engine:commit_text(text:sub(1, utf8.offset(text, 2) - 1))
|
engine:commit_text(text:sub(1, utf8.offset(text, 2) - 1))
|
||||||
context:clear()
|
context:clear()
|
||||||
return 1
|
return 1
|
||||||
elseif (key:repr() == select.last_key) then
|
elseif (key:repr() == env.last_key) then
|
||||||
engine:commit_text(text:sub(utf8.offset(text, -1)))
|
engine:commit_text(text:sub(utf8.offset(text, -1)))
|
||||||
context:clear()
|
context:clear()
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
if key:repr() == env.first_key or key:repr() == env.last_key then
|
||||||
|
engine:commit_text(text)
|
||||||
|
context:clear()
|
||||||
|
return 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 2
|
return 2
|
||||||
|
Loading…
Reference in New Issue
Block a user