Skip to content

Commit

Permalink
Fix typing with exact match mode on and auto select
Browse files Browse the repository at this point in the history
1. require auto select to only select when code is fully matched.
   Certain table's prefix has only one match, since the code is defined
   as the longer version, we should always require auto select to match
   the full code. Otherwise, user may always update the table to make
   that a short code.
2. When exact matching mode is on, we need to indeed check if it is the
   only match, otherwise certain code may not be possible to be typed.

Fix fcitx/fcitx5-chinese-addons#150
  • Loading branch information
wengxt committed Nov 2, 2023
1 parent 3b9110e commit 0b4d875
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/libime/table/tablebaseddictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,17 +1324,18 @@ bool TableBasedDictionary::hasMatchingWords(std::string_view code) const {
}

bool TableBasedDictionary::hasOneMatchingWord(std::string_view code) const {
bool hasMatch = false;
bool hasOneMatch = false;
matchWords(
code, TableMatchMode::Prefix,
[&hasMatch](std::string_view, std::string_view, uint32_t, PhraseFlag) {
if (hasMatch) {
[&hasOneMatch](std::string_view, std::string_view, uint32_t, PhraseFlag) {
if (hasOneMatch) {
hasOneMatch = false;
return false;
}
hasMatch = true;
hasOneMatch = true;
return true;
});
return hasMatch;
return hasOneMatch;
}

PhraseFlag TableBasedDictionary::wordExists(std::string_view code,
Expand Down
12 changes: 11 additions & 1 deletion src/libime/table/tablecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,17 @@ class TableContextPrivate : public fcitx::QPtrHolder<TableContext> {
if (!canDoAutoSelect()) {
return false;
}
return candidates_.size() == 1;
if (candidates_.size() != 1) {
return false;
}

if (candidates_[0].sentence().size() != 1) {
return false;
}
FCITX_Q();
return q->code(candidates_[0]) == q->currentCode() &&
(!dict_.tableOptions().exactMatch() ||
dict_.hasOneMatchingWord(q->currentCode()));
};

State currentState() {
Expand Down

0 comments on commit 0b4d875

Please sign in to comment.