-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new APIs, peek selection and change page #620
Changes from all commits
9aa83e6
ecd3649
5c1502e
0de4da0
fbc709e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,17 +110,35 @@ void Context::Clear() { | |
} | ||
|
||
bool Context::Select(size_t index) { | ||
if (composition_.empty()) | ||
bool result = Peek(index); | ||
if (result) { | ||
composition_.back().status = Segment::kSelected; | ||
select_notifier_(this); | ||
} | ||
return result; | ||
} | ||
|
||
bool Context::Peek(size_t index) { | ||
if (composition_.empty() || !composition_.back().menu) | ||
return false; | ||
Segment& seg(composition_.back()); | ||
if (auto cand = seg.GetCandidateAt(index)) { | ||
seg.selected_index = index; | ||
seg.status = Segment::kSelected; | ||
DLOG(INFO) << "Selected: '" << cand->text() << "', index = " << index; | ||
select_notifier_(this); | ||
return true; | ||
size_t new_index = index; | ||
if (index < 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback feature is convenient in highlighting the candidate of the same label number in the next page. But when called by |
||
} | ||
} | ||
return false; | ||
size_t previous_index = seg.selected_index; | ||
seg.selected_index = new_index; | ||
update_notifier_(this); | ||
|
||
DLOG(INFO) << "Selection changed from: " << previous_index << " to: " << new_index; | ||
return true; | ||
} | ||
|
||
bool Context::DeleteCandidate( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback mechanism of
Peek
does not work forSelect
. See my other comment below.Also, this creates a difference in the signaled notifications: an extra
update_notifier_
is triggered beforeselect_notifier_
.I think we'd better keep the two functions separate.