Skip to content

Commit 396e646

Browse files
authored
synchronously reset and directly commit for symbol selector (#36)
1 parent f1e8ce8 commit 396e646

File tree

8 files changed

+21
-9
lines changed

8 files changed

+21
-9
lines changed

entry/src/main/cpp/harmonyfrontend/harmonyfrontend.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ void HarmonyFrontend::focusIn(bool clientPreedit) {
3333

3434
void HarmonyFrontend::focusOut() { ic_->focusOut(); }
3535

36-
void HarmonyFrontend::reset() { ic_->reset(); }
36+
InputContextState HarmonyFrontend::reset() {
37+
ic_->isSyncEvent = true;
38+
ic_->reset();
39+
return ic_->popState(true);
40+
}
3741

3842
HarmonyInputContext::HarmonyInputContext(HarmonyFrontend *frontend, InputContextManager &inputContextManager)
3943
: InputContext(inputContextManager, ""), frontend_(frontend) {

entry/src/main/cpp/harmonyfrontend/harmonyfrontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class HarmonyFrontend : public AddonInstance {
2525
InputContextState keyEvent(const Key &key, bool isRelease);
2626
void focusIn(bool clientPreedit);
2727
void focusOut();
28-
void reset();
28+
InputContextState reset();
2929

3030
private:
3131
Instance *instance_;

entry/src/main/cpp/napi_init.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ API(focusOut) {
2424
}
2525

2626
API(reset) {
27-
fcitx::reset();
28-
return {};
27+
auto state = fcitx::reset();
28+
OBJECT(ret)
29+
SET(ret, "commit", state.commit)
30+
SET(ret, "preedit", state.preedit)
31+
SET(ret, "cursorPos", state.cursorPos)
32+
SET(ret, "accepted", state.accepted)
33+
return ret;
2934
}
3035

3136
API(processKey) {

entry/src/main/cpp/src/fcitx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ void focusOut() {
8888
with_fcitx([] { frontend->focusOut(); });
8989
}
9090

91-
void reset() {
92-
with_fcitx([] { frontend->reset(); });
91+
InputContextState reset() {
92+
return with_fcitx([] { return frontend->reset(); });
9393
}
9494

9595
InputContextState processKey(uint32_t unicode, int32_t keyCode, bool isRelease) {

entry/src/main/cpp/src/fcitx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct InputContextState {
1818
void init(const std::string &bundle, const std::string &resfile);
1919
void focusIn(bool clientPreedit);
2020
void focusOut();
21-
void reset();
21+
InputContextState reset();
2222
InputContextState processKey(uint32_t unicode, int32_t keyCode, bool isRelease);
2323
void selectCandidate(int index);
2424
void activateStatusAreaAction(int id);

entry/src/main/cpp/types/libentry/Index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export const init: (bundle: string, resfile: string) => void
22
export const setCallback: (callback: (data: string) => void) => void
33
export const focusIn: (clientPreedit: boolean) => void
44
export const focusOut: () => void
5-
export const reset: () => void
65

76
export interface InputContextState {
87
commit: string
@@ -11,5 +10,6 @@ export interface InputContextState {
1110
accepted: boolean
1211
}
1312
export const processKey: (unicode: number, keyCode: number, isRelease: boolean) => InputContextState
13+
export const reset: () => InputContextState
1414
export const selectCandidate: (index: number) => void
1515
export const activateStatusAreaAction: (index: number) => void

entry/src/main/ets/InputMethodExtensionAbility/model/KeyboardController.ets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ export class KeyboardController {
249249
switch (event.type) {
250250
case 'COLLAPSE':
251251
return this.panel?.hide()
252+
case 'COMMIT':
253+
this.processResult(fcitx.reset())
254+
return this.insertText(event.data)
252255
case 'COPY':
253256
return this.textInputClient?.sendExtendAction(inputMethodEngine.ExtendAction.COPY)
254257
case 'CUT':

0 commit comments

Comments
 (0)