Skip to content

Commit

Permalink
Add short hand append for candidate list.
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Feb 13, 2020
1 parent 8bee2b2 commit 9436416
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/im/keyboard/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ void KeyboardEngine::updateCandidate(const InputMethodEntry &entry,
auto candidateList = std::make_unique<CommonCandidateList>();
auto spellType = guessSpellType(state->buffer_.userInput());
for (const auto &result : results) {
candidateList->append(std::make_unique<KeyboardCandidateWord>(
this, Text(formatWord(result, spellType))));
candidateList->append<KeyboardCandidateWord>(
this, Text(formatWord(result, spellType)));
}
candidateList->setSelectionKey(selectionKeys_);
candidateList->setCursorIncludeUnselected(true);
Expand Down
6 changes: 6 additions & 0 deletions src/lib/fcitx/candidatelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ class FCITXCORE_EXPORT ModifiableCandidateList : public BulkCandidateList {
void append(std::unique_ptr<CandidateWord> word) {
insert(totalSize(), std::move(word));
}

template <typename CandidateWordType, typename... Args>
void append(Args &&... args) {
append(
std::make_unique<CandidateWordType>(std::forward<Args>(args)...));
}
};

class DisplayOnlyCandidateListPrivate;
Expand Down
9 changes: 3 additions & 6 deletions src/modules/clipboard/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ void Clipboard::updateUI(InputContext *inputContext) {
// Append first item from history_.
auto iter = history_.begin();
if (iter != history_.end()) {
candidateList->append(
std::make_unique<ClipboardCandidateWord>(this, *iter));
candidateList->append<ClipboardCandidateWord>(this, *iter);
iter++;
}
// Append primary_, but check duplication first.
Expand All @@ -279,17 +278,15 @@ void Clipboard::updateUI(InputContext *inputContext) {
}
}
if (!dup) {
candidateList->append(
std::make_unique<ClipboardCandidateWord>(this, primary_));
candidateList->append<ClipboardCandidateWord>(this, primary_);
}
}
// If primary_ is appended, it might squeeze one space out.
for (; iter != history_.end(); iter++) {
if (candidateList->totalSize() >= config_.numOfEntries.value()) {
break;
}
candidateList->append(
std::make_unique<ClipboardCandidateWord>(this, *iter));
candidateList->append<ClipboardCandidateWord>(this, *iter);
}
candidateList->setSelectionKey(selectionKeys_);
candidateList->setLayoutHint(CandidateLayoutHint::Vertical);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/quickphrase/quickphrase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ void QuickPhrase::updateUI(InputContext *inputContext) {
text.append(start->second);
text.append(" ");
text.append(start->first.substr(state->buffer_.userInput().size()));
candidateList->append(std::make_unique<QuickPhraseCandidateWord>(
this, std::move(text)));
candidateList->append<QuickPhraseCandidateWord>(this,
std::move(text));
}
candidateList->setSelectionKey(selectionKeys_);
inputContext->inputPanel().setCandidateList(std::move(candidateList));
Expand Down
3 changes: 1 addition & 2 deletions src/modules/unicode/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ void Unicode::updateUI(InputContext *inputContext) {
candidateList->setPageSize(instance_->globalConfig().defaultPageSize());
for (auto c : result) {
if (utf8::UCS4IsValid(c)) {
candidateList->append(
std::make_unique<UnicodeCandidateWord>(this, c));
candidateList->append<UnicodeCandidateWord>(this, c);
}
}
candidateList->setSelectionKey(selectionKeys_);
Expand Down
2 changes: 1 addition & 1 deletion test/testcandidatelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main() {
Key::keyListFromString("1 2 3 4 5 6 7 8 9 0"));
candidatelist.setPageSize(3);
for (int i = 0; i < 10; i++) {
candidatelist.append(std::make_unique<TestCandidateWord>(i));
candidatelist.append<TestCandidateWord>(i);
}

FCITX_ASSERT(candidatelist.size() == 3);
Expand Down

0 comments on commit 9436416

Please sign in to comment.