Only forget the candidate the user picked from the menu

The menu remembered the index of the candidate it was opened on. Cloud Pinyin
results arrive asynchronously, so the list can be refreshed between the right
click and the click on an action, and the index would then point at a different
word. That word would have been forgotten and added to the block list.

The word itself is stored when the menu opens and compared when an action is
clicked, nothing is done if it is no longer the same.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
justmeandClaude Sonnet 5.5 committed 2026-10-19 23:36:54 +08:00
1 parent bf3c88acc8
commit ce0d6ba9ae
2 files changed
+13 -2

No files matched your search

+9 -2
View File
@@ -977,6 +977,7 @@ void InputWindow::click(int x, int y) {
int actionId = -1;
std::string actionText;
const auto candidateIndex = menuCandidate_;
const std::string candidateText = menuCandidateText_;
for (size_t i = 0; i < menuRegions_.size(); i++) {
if (menuRegions_[i].contains(x, y)) {
actionId = menuActions_[i].id();
@@ -989,11 +990,15 @@ void InputWindow::click(int x, int y) {
auto *actionable = candidateList->toActionable();
const auto *candidate =
nthCandidateIgnorePlaceholder(*candidateList, candidateIndex);
if (actionable && candidate) {
// The list may have been refreshed since the menu was opened. Only
// act when the candidate is still the one the user picked, a
// different word must never be forgotten or blocked.
if (actionable && candidate &&
candidate->text().toString() == candidateText) {
// Block before the engine refreshes its list so the refreshed
// list is already filtered.
if (isForgetAction(actionText)) {
parent_->blockWord(candidate->text().toString());
parent_->blockWord(candidateText);
}
actionable->triggerAction(*candidate, actionId);
}
@@ -1065,6 +1070,7 @@ void InputWindow::rightClick(int x, int y) {
}
menuActions_ = std::move(actions);
menuCandidate_ = idx;
menuCandidateText_ = candidate->text().toString();
menuHover_ = -1;
menuOpen_ = true;
inputContext->updateUserInterface(UserInterfaceComponent::InputPanel);
@@ -1075,6 +1081,7 @@ void InputWindow::rightClick(int x, int y) {
void InputWindow::closeMenu() {
menuOpen_ = false;
menuCandidate_ = -1;
menuCandidateText_.clear();
menuHover_ = -1;
menuActions_.clear();
menuRegions_.clear();
+4
View File
@@ -198,6 +198,10 @@ protected:
std::pair<double, double> menuSize();
bool menuOpen_ = false;
int menuCandidate_ = -1;
// The word the menu was opened on. The list can be refreshed between the
// right click and the click on an action, the index alone would then point
// at a different word.
std::string menuCandidateText_;
int menuHover_ = -1;
std::vector<CandidateAction> menuActions_;
std::vector<Rect> menuRegions_;