@@ -45,53 +45,6 @@ const char imNamePrefix[] = "keyboard-";
4545namespace fcitx {
4646
4747namespace {
48- enum class SpellType { AllLower, Mixed, FirstUpper, AllUpper };
49-
50- SpellType guessSpellType (const std::string &input) {
51- if (input.size () <= 1 ) {
52- if (charutils::isupper (input[0 ])) {
53- return SpellType::FirstUpper;
54- }
55- return SpellType::AllLower;
56- }
57-
58- if (std::all_of (input.begin (), input.end (),
59- [](char c) { return charutils::isupper (c); })) {
60- return SpellType::AllUpper;
61- }
62-
63- if (std::all_of (input.begin () + 1 , input.end (),
64- [](char c) { return charutils::islower (c); })) {
65- if (charutils::isupper (input[0 ])) {
66- return SpellType::FirstUpper;
67- }
68- return SpellType::AllLower;
69- }
70-
71- return SpellType::Mixed;
72- }
73-
74- std::string formatWord (const std::string &input, SpellType type) {
75- if (type == SpellType::Mixed || type == SpellType::AllLower) {
76- return input;
77- }
78- if (guessSpellType (input) != SpellType::AllLower) {
79- return input;
80- }
81- std::string result;
82- if (type == SpellType::AllUpper) {
83- result.reserve (input.size ());
84- std::transform (input.begin (), input.end (), std::back_inserter (result),
85- charutils::toupper);
86- } else {
87- // FirstUpper
88- result = input;
89- if (!result.empty ()) {
90- result[0 ] = charutils::toupper (result[0 ]);
91- }
92- }
93- return result;
94- }
9548
9649std::string findBestLanguage (const IsoCodes &isocodes, const std::string &hint,
9750 const std::vector<std::string> &languages) {
@@ -155,20 +108,23 @@ std::string findBestLanguage(const IsoCodes &isocodes, const std::string &hint,
155108
156109class KeyboardCandidateWord : public CandidateWord {
157110public:
158- KeyboardCandidateWord (KeyboardEngine *engine, Text text)
159- : CandidateWord(std::move(text)), engine_(engine) {}
111+ KeyboardCandidateWord (KeyboardEngine *engine, Text text, std::string commit)
112+ : CandidateWord(std::move(text)), engine_(engine),
113+ commit_ (std::move(commit)) {}
160114
161115 void select (InputContext *inputContext) const override {
162- auto commit = text ().toString ();
163116 inputContext->inputPanel ().reset ();
164117 inputContext->updatePreedit ();
165118 inputContext->updateUserInterface (UserInterfaceComponent::InputPanel);
166- inputContext->commitString (commit );
119+ inputContext->commitString (commit_ );
167120 engine_->resetState (inputContext);
168121 }
169122
123+ const std::string &stringForCommit () const { return commit_; }
124+
170125private:
171126 KeyboardEngine *engine_;
127+ std::string commit_;
172128};
173129
174130class LongPressCandidateWord : public CandidateWord {
@@ -515,11 +471,11 @@ void KeyboardEngineState::setPreedit() {
515471
516472void KeyboardEngineState::updateCandidate (const InputMethodEntry &entry) {
517473 inputContext_->inputPanel ().reset ();
518- std::vector<std::string> results;
474+ std::vector<std::pair<std:: string, std::string> > results;
519475 if (auto spell = engine_->spell ()) {
520- results =
521- spell-> call <ISpell::hint>( entry.languageCode (), buffer_.userInput (),
522- engine_->config ().pageSize .value ());
476+ results = spell-> call <ISpell::hintForDisplay>(
477+ entry.languageCode (), SpellProvider::Default , buffer_.userInput (),
478+ engine_->config ().pageSize .value ());
523479 }
524480 if (engine_->config ().enableEmoji .value () && engine_->emoji ()) {
525481 auto emojiResults = engine_->emoji ()->call <IEmoji::query>(
@@ -535,16 +491,15 @@ void KeyboardEngineState::updateCandidate(const InputMethodEntry &entry) {
535491 while (i < emojiResults.size () &&
536492 static_cast <int >(results.size ()) <
537493 engine_->config ().pageSize .value ()) {
538- results.push_back ( emojiResults[i]);
494+ results.emplace_back (emojiResults[i], emojiResults[i]);
539495 i++;
540496 }
541497 }
542498
543499 auto candidateList = std::make_unique<CommonCandidateList>();
544- auto spellType = guessSpellType (buffer_.userInput ());
545500 for (const auto &result : results) {
546501 candidateList->append <KeyboardCandidateWord>(
547- engine_, Text (formatWord ( result, spellType)) );
502+ engine_, Text (result. first ), result. second );
548503 }
549504 candidateList->setPageSize (*engine_->config ().pageSize );
550505 candidateList->setSelectionKey (engine_->selectionKeys ());
@@ -825,7 +780,7 @@ std::string KeyboardEngineState::currentSelection() const {
825780 dynamic_cast <const KeyboardCandidateWord *>(
826781 &candidateList->candidate (
827782 candidateList->cursorIndex ()))) {
828- return candidate->text (). toString ();
783+ return candidate->stringForCommit ();
829784 }
830785 }
831786 return buffer_.userInput ();
0 commit comments