From cdbc79985afdb3cce931bdba3636f29e1cadaef3 Mon Sep 17 00:00:00 2001 From: abcdefg233 <32760059+abcdefg233@users.noreply.github.com> Date: Fri, 26 May 2023 21:04:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=A5=E8=AF=8D=E5=AE=9A=E5=AD=97?= =?UTF-8?q?=E5=8F=96=E5=AD=97=E9=80=BB=E8=BE=91=20(#293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复的问题:在翻页后按下取最后一个字的快捷键,取到的是拼音的最后一个字母。 --- lua/select_character.lua | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/lua/select_character.lua b/lua/select_character.lua index 315d7ff..0839651 100644 --- a/lua/select_character.lua +++ b/lua/select_character.lua @@ -1,6 +1,7 @@ -- 以词定字 -- 来源 https://github.com/BlindingDark/rime-lua-select-character -- 删除了默认按键 [ ],和方括号翻页冲突,需要在 key_binder 下指定才能生效 +-- 20230526195910 不再错误地获取commit_text,而是直接获取get_selected_candidate().text。 local function utf8_sub(s, i, j) i = i or 1 j = j or -1 @@ -44,14 +45,6 @@ local function utf8_sub(s, i, j) end end -local function first_character(s) - return utf8_sub(s, 1, 1) -end - -local function last_character(s) - return utf8_sub(s, -1, -1) -end - local function select_character(key, env) local engine = env.engine local context = engine.context @@ -63,17 +56,19 @@ local function select_character(key, env) local first_key = config:get_string('key_binder/select_first_character') local last_key = config:get_string('key_binder/select_last_character') - if (key:repr() == first_key and commit_text ~= "") then - engine:commit_text(first_character(commit_text)) - context:clear() - + if (key:repr() == first_key) then + if(context:get_selected_candidate().text)then + engine:commit_text(utf8_sub(context:get_selected_candidate().text, 1, 1)) + context:clear() + end return 1 -- kAccepted end - if (key:repr() == last_key and commit_text ~= "") then - engine:commit_text(last_character(commit_text)) - context:clear() - + if (key:repr() == last_key) then + if(context:get_selected_candidate().text)then + engine:commit_text(utf8_sub(context:get_selected_candidate().text,-1,-1)) + context:clear() + end return 1 -- kAccepted end