From 58f6ad693739f833675ea5727f931ed295915b66 Mon Sep 17 00:00:00 2001 From: LEO Yoon-Tsaw Date: Sat, 27 Apr 2024 17:17:08 -0400 Subject: [PATCH 1/4] Update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6ec9dae1d1..47b822092c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ node_modules/ .*.swp .cache/ *.7z +*.DS_Store +plugins/librime-* From 8e1c16108ac201bd31637d0889b11b8ed7476533 Mon Sep 17 00:00:00 2001 From: LEO Yoon-Tsaw Date: Sat, 27 Apr 2024 20:43:27 -0400 Subject: [PATCH 2/4] Fix Context::Highlight --- src/rime/context.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/rime/context.cc b/src/rime/context.cc index 34ca645231..a8d8e3f2e9 100644 --- a/src/rime/context.cc +++ b/src/rime/context.cc @@ -128,10 +128,15 @@ bool Context::Highlight(size_t index) { return false; Segment& seg(composition_.back()); size_t new_index = index; - size_t candidate_count = seg.menu->Prepare(index + 1); - if (index >= candidate_count) { - DLOG(INFO) << "selection index exceeds candidate pool, fallback to last"; - new_index = candidate_count - 1; + if (index < 0) { + DLOG(INFO) << "selection index < 0, fallback to 0"; + new_index = 0; + } else { + size_t candidate_count = seg.menu->Prepare(index + 1); + if (index >= candidate_count) { + DLOG(INFO) << "selection index exceed candidate pool, fallback to last"; + new_index = candidate_count - 1; + } } size_t previous_index = seg.selected_index; if (previous_index == new_index) { From 42922e1d9c710f295e65561c314f8648543641ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E6=88=8E=E6=B0=8F?= Date: Sun, 28 Apr 2024 14:23:56 +0800 Subject: [PATCH 3/4] Revert "Update gitignore" This reverts commit 58f6ad693739f833675ea5727f931ed295915b66. --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 47b822092c..6ec9dae1d1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,3 @@ node_modules/ .*.swp .cache/ *.7z -*.DS_Store -plugins/librime-* From 40ddd5692e31b7ad8a0edf840fc4a48d0d4b8aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=85=E6=88=8E=E6=B0=8F?= Date: Sun, 28 Apr 2024 14:31:07 +0800 Subject: [PATCH 4/4] clamp new_index between 0 and candidate_count - 1 when candidate_count > 0; otherwise new_index = 0. --- src/rime/context.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/rime/context.cc b/src/rime/context.cc index a8d8e3f2e9..a63537dd32 100644 --- a/src/rime/context.cc +++ b/src/rime/context.cc @@ -4,6 +4,7 @@ // // 2011-05-08 GONG Chen // +#include #include #include #include @@ -127,17 +128,9 @@ bool Context::Highlight(size_t index) { if (composition_.empty() || !composition_.back().menu) return false; Segment& seg(composition_.back()); - size_t new_index = index; - if (index < 0) { - DLOG(INFO) << "selection index < 0, fallback to 0"; - new_index = 0; - } else { - size_t candidate_count = seg.menu->Prepare(index + 1); - if (index >= candidate_count) { - DLOG(INFO) << "selection index exceed candidate pool, fallback to last"; - new_index = candidate_count - 1; - } - } + size_t candidate_count = seg.menu->Prepare(index + 1); + size_t new_index = + candidate_count > 0 ? (std::min)(candidate_count - 1, index) : 0; size_t previous_index = seg.selected_index; if (previous_index == new_index) { DLOG(INFO) << "selection has not changed, currently at " << new_index;