@@ -45,53 +45,6 @@ const char imNamePrefix[] = "keyboard-";
45
45
namespace fcitx {
46
46
47
47
namespace {
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
- }
95
48
96
49
std::string findBestLanguage (const IsoCodes &isocodes, const std::string &hint,
97
50
const std::vector<std::string> &languages) {
@@ -155,20 +108,23 @@ std::string findBestLanguage(const IsoCodes &isocodes, const std::string &hint,
155
108
156
109
class KeyboardCandidateWord : public CandidateWord {
157
110
public:
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)) {}
160
114
161
115
void select (InputContext *inputContext) const override {
162
- auto commit = text ().toString ();
163
116
inputContext->inputPanel ().reset ();
164
117
inputContext->updatePreedit ();
165
118
inputContext->updateUserInterface (UserInterfaceComponent::InputPanel);
166
- inputContext->commitString (commit );
119
+ inputContext->commitString (commit_ );
167
120
engine_->resetState (inputContext);
168
121
}
169
122
123
+ const std::string &stringForCommit () const { return commit_; }
124
+
170
125
private:
171
126
KeyboardEngine *engine_;
127
+ std::string commit_;
172
128
};
173
129
174
130
class LongPressCandidateWord : public CandidateWord {
@@ -515,11 +471,11 @@ void KeyboardEngineState::setPreedit() {
515
471
516
472
void KeyboardEngineState::updateCandidate (const InputMethodEntry &entry) {
517
473
inputContext_->inputPanel ().reset ();
518
- std::vector<std::string> results;
474
+ std::vector<std::pair<std:: string, std::string> > results;
519
475
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 ());
523
479
}
524
480
if (engine_->config ().enableEmoji .value () && engine_->emoji ()) {
525
481
auto emojiResults = engine_->emoji ()->call <IEmoji::query>(
@@ -535,16 +491,15 @@ void KeyboardEngineState::updateCandidate(const InputMethodEntry &entry) {
535
491
while (i < emojiResults.size () &&
536
492
static_cast <int >(results.size ()) <
537
493
engine_->config ().pageSize .value ()) {
538
- results.push_back ( emojiResults[i]);
494
+ results.emplace_back (emojiResults[i], emojiResults[i]);
539
495
i++;
540
496
}
541
497
}
542
498
543
499
auto candidateList = std::make_unique<CommonCandidateList>();
544
- auto spellType = guessSpellType (buffer_.userInput ());
545
500
for (const auto &result : results) {
546
501
candidateList->append <KeyboardCandidateWord>(
547
- engine_, Text (formatWord ( result, spellType)) );
502
+ engine_, Text (result. first ), result. second );
548
503
}
549
504
candidateList->setPageSize (*engine_->config ().pageSize );
550
505
candidateList->setSelectionKey (engine_->selectionKeys ());
@@ -825,7 +780,7 @@ std::string KeyboardEngineState::currentSelection() const {
825
780
dynamic_cast <const KeyboardCandidateWord *>(
826
781
&candidateList->candidate (
827
782
candidateList->cursorIndex ()))) {
828
- return candidate->text (). toString ();
783
+ return candidate->stringForCommit ();
829
784
}
830
785
}
831
786
return buffer_.userInput ();
0 commit comments