From 8d4e432d47b6084d1b711f8c551afdae603562a8 Mon Sep 17 00:00:00 2001 From: amzxyz Date: Thu, 25 Dec 2025 21:05:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=88=E5=A4=9A=E8=A2=AB=E5=A4=A7?= =?UTF-8?q?=E5=8E=82=E6=83=AF=E5=9D=8F=E7=9A=84=E7=94=A8=E6=88=B7=E8=AE=A4?= =?UTF-8?q?=E4=B8=BA=E8=AE=BE=E7=BD=AE=E6=88=909=E4=B8=AA=E8=83=BD?= =?UTF-8?q?=E8=AE=A9=E8=87=AA=E5=B7=B1=E4=B8=8D=E7=94=A8=E7=BF=BB=E9=A1=B5?= =?UTF-8?q?=EF=BC=8C=E6=88=91=E5=86=8D=E5=A4=9A=E5=AE=A0=E7=88=B1=E4=B8=80?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E7=8E=B0=E5=9C=A8=E4=BD=A0=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=8C=89=E4=B8=8B0=E4=B8=8A=E5=B1=8F=E7=AC=AC10=E4=B8=AA?= =?UTF-8?q?=E5=80=99=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/kp_number_processor.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/kp_number_processor.lua b/lua/kp_number_processor.lua index 1fdc2b6..490e5ee 100644 --- a/lua/kp_number_processor.lua +++ b/lua/kp_number_processor.lua @@ -223,22 +223,25 @@ function P.func(key, env) -- 有候选菜单时,用数字选「当前页」的第 n 个候选 if has_menu then local d = tonumber(r) + -- 如果按下的是 0,视为第 10 个选项 + if d == 0 then d = 10 end + -- 检查是否在有效范围内 (例如 page_size 是 10,那么 1-10 都有效) if d and d >= 1 and d <= page_sz then local composition = context and context.composition if composition and not composition:empty() then - local seg = composition:back() -- 当前正在编辑的 segment + local seg = composition:back() local menu = seg and seg.menu if menu and not menu:empty() then - -- 当前高亮候选的全局下标(0 开始) local sel_index = seg.selected_index or 0 local page_size = page_sz - -- 当前页号 = 高亮索引 / 每页大小 + -- 计算当前页起始位置 local page_no = math.floor(sel_index / page_size) local page_start = page_no * page_size - -- 当前页第 n 个候选的全局下标 + + -- 计算目标候选的全局下标 (d=10 则取第10个) local index = page_start + (d - 1) - -- 防止越界(最后一页候选不足一整页) + -- 防止越界并执行上屏 if index < menu:candidate_count() then if context:select(index) then return wanxiang.RIME_PROCESS_RESULTS.kAccepted @@ -247,6 +250,8 @@ function P.func(key, env) end end end + -- 如果数字超出了 page_size (例如设置每页6个,按了7), + -- 或者没有选中成功,返回 kNoop,交给 Rime 默认处理 return wanxiang.RIME_PROCESS_RESULTS.kNoop end end