diff --git a/src/rime/context.cc b/src/rime/context.cc index 34ca645231..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,12 +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; 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; - } + 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;