Skip to content

Commit

Permalink
reset on click inside textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Dec 17, 2024
1 parent eb4b55e commit 7dddd87
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions page/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ export function clickPanel() {
userClick = true
}

function resetInput() {
Module.ccall('reset_input', 'void', [], [])
}

export function focus() {
if (!['INPUT', 'TEXTAREA'].includes(document.activeElement?.tagName || '')) {
return
}
input = <Input>document.activeElement
input.addEventListener('mousedown', resetInput)
Module.ccall('focus_in', 'void', [], [])
}

Expand All @@ -27,6 +32,7 @@ export function blur() {
userClick = false
return
}
input.removeEventListener('mousedown', resetInput)
input = null
Module.ccall('focus_out', 'void', [], [])
resetPreedit()
Expand Down
2 changes: 2 additions & 0 deletions src/fcitx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ EMSCRIPTEN_KEEPALIVE void focus_in() { frontend->focusIn(); }

EMSCRIPTEN_KEEPALIVE void focus_out() { frontend->focusOut(); }

EMSCRIPTEN_KEEPALIVE void reset_input() { frontend->resetInput(); }

EMSCRIPTEN_KEEPALIVE bool process_key(const char *key, const char *code,
uint32_t modifiers, bool isRelease) {
return frontend->keyEvent(js_key_to_fcitx_key(key, code, modifiers),
Expand Down
2 changes: 2 additions & 0 deletions wasmfrontend/wasmfrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void WasmFrontend::focusIn() { ic_->focusIn(); }

void WasmFrontend::focusOut() { ic_->focusOut(); }

void WasmFrontend::resetInput() { ic_->reset(); }

WasmInputContext::WasmInputContext(WasmFrontend *frontend,
InputContextManager &inputContextManager)
: InputContext(inputContextManager, ""), frontend_(frontend) {
Expand Down
1 change: 1 addition & 0 deletions wasmfrontend/wasmfrontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WasmFrontend : public AddonInstance {
bool keyEvent(const Key &key, bool isRelease);
void focusIn();
void focusOut();
void resetInput();

private:
Instance *instance_;
Expand Down

0 comments on commit 7dddd87

Please sign in to comment.