@@ -38,6 +38,7 @@ namespace fcitx {
38
38
std::unique_ptr<Instance> instance;
39
39
std::unique_ptr<fcitx::EventDispatcher> dispatcher;
40
40
HarmonyFrontend *frontend;
41
+ WebKeyboard *ui;
41
42
42
43
static native_streambuf log_streambuf;
43
44
static std::ostream stream (&log_streambuf);
@@ -81,6 +82,7 @@ void init(const std::string &bundle, const std::string &resfile) {
81
82
dispatcher->attach (&instance->eventLoop ());
82
83
fcitx_thread = std::thread ([] { instance->eventLoop ().exec (); });
83
84
frontend = dynamic_cast <HarmonyFrontend *>(addonMgr.addon (" harmonyfrontend" ));
85
+ ui = dynamic_cast <WebKeyboard *>(addonMgr.addon (" webkeyboard" ));
84
86
setInputMethods ({" keyboard-us" , " keyboard-th" , " pinyin" }); // XXX: for test only.
85
87
}
86
88
@@ -109,6 +111,15 @@ void selectCandidate(int index) {
109
111
const auto &list = ic->inputPanel ().candidateList ();
110
112
if (!list)
111
113
return ;
114
+ const auto &bulk = list->toBulk ();
115
+ if (bulk) {
116
+ try {
117
+ bulk->candidateFromAll (index).select (ic);
118
+ } catch (const std::invalid_argument &e) {
119
+ FCITX_ERROR () << " select candidate index out of range" ;
120
+ }
121
+ return ;
122
+ }
112
123
try {
113
124
// Engine is responsible for updating UI
114
125
list->candidate (index).select (ic);
@@ -118,6 +129,17 @@ void selectCandidate(int index) {
118
129
});
119
130
}
120
131
132
+ static void answerCandidateAction (ActionableCandidateList *actionableList, const CandidateWord &candidate, int index) {
133
+ if (actionableList->hasAction (candidate)) {
134
+ json actions = json::array ();
135
+ for (const auto &action : actionableList->candidateActions (candidate)) {
136
+ actions.push_back ({{" id" , action.id ()}, {" text" , action.text ()}});
137
+ }
138
+ notify_main_async (
139
+ json{{" type" , " CANDIDATE_ACTIONS" }, {" data" , {{" index" , index}, {" actions" , actions}}}}.dump ());
140
+ }
141
+ }
142
+
121
143
void askCandidateAction (int index) {
122
144
with_fcitx ([index] {
123
145
auto ic = instance->mostRecentInputContext ();
@@ -128,16 +150,19 @@ void askCandidateAction(int index) {
128
150
if (!actionableList) {
129
151
return ;
130
152
}
153
+ const auto &bulk = list->toBulk ();
154
+ if (bulk) {
155
+ try {
156
+ auto &candidate = bulk->candidateFromAll (index);
157
+ answerCandidateAction (actionableList, candidate, index);
158
+ } catch (const std::invalid_argument &e) {
159
+ FCITX_ERROR () << " action candidate index out of range" ;
160
+ }
161
+ return ;
162
+ }
131
163
try {
132
164
auto &candidate = list->candidate (index);
133
- if (actionableList->hasAction (candidate)) {
134
- json actions = json::array ();
135
- for (const auto &action : actionableList->candidateActions (candidate)) {
136
- actions.push_back ({{" id" , action.id ()}, {" text" , action.text ()}});
137
- }
138
- notify_main_async (
139
- json{{" type" , " CANDIDATE_ACTIONS" }, {" data" , {{" index" , index}, {" actions" , actions}}}}.dump ());
140
- }
165
+ answerCandidateAction (actionableList, candidate, index);
141
166
} catch (const std::invalid_argument &e) {
142
167
FCITX_ERROR () << " action candidate index out of range" ;
143
168
}
@@ -154,6 +179,18 @@ void activateCandidateAction(int index, int id) {
154
179
if (!actionableList) {
155
180
return ;
156
181
}
182
+ const auto &bulk = list->toBulk ();
183
+ if (bulk) {
184
+ try {
185
+ const auto &candidate = bulk->candidateFromAll (index);
186
+ if (actionableList->hasAction (candidate)) {
187
+ actionableList->triggerAction (candidate, id);
188
+ }
189
+ } catch (const std::invalid_argument &e) {
190
+ FCITX_ERROR () << " action candidate index out of range" ;
191
+ }
192
+ return ;
193
+ }
157
194
try {
158
195
auto &candidate = list->candidate (index);
159
196
if (actionableList->hasAction (candidate)) {
@@ -181,4 +218,8 @@ void toggle() {
181
218
void setCurrentInputMethod (const std::string &inputMethod) {
182
219
with_fcitx ([&] { instance->setCurrentInputMethod (inputMethod); });
183
220
}
221
+
222
+ void scroll (int start, int count) {
223
+ with_fcitx ([=] { ui->scroll (start, count); });
224
+ }
184
225
} // namespace fcitx
0 commit comments