Skip to content

Commit d9f803c

Browse files
committed
support password input
1 parent 3aed611 commit d9f803c

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

page/focus.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export function focus() {
4242
redrawCaret({ target: input })
4343
}
4444
originalSpellCheck = input.spellcheck
45-
Module.ccall('focus_in', 'void', [], [])
45+
const isPassword = input.tagName === 'INPUT' && input.type === 'password'
46+
Module.ccall('focus_in', 'void', ['bool'], [isPassword])
4647
}
4748

4849
export function blur() {

src/fcitx.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ static void answerCandidateAction(ActionableCandidateList *actionableList,
3939

4040
extern "C" {
4141

42-
EMSCRIPTEN_KEEPALIVE void focus_in() { frontend->focusIn(); }
42+
EMSCRIPTEN_KEEPALIVE void focus_in(bool isPassword) {
43+
frontend->focusIn(isPassword);
44+
}
4345

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

tests/test-generic.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,23 @@ test('keyboard-th', async ({ page }) => {
3737
}
3838
await expect(textarea).toHaveValue('สวัสดี')
3939
})
40+
41+
test('Password', async ({ page }) => {
42+
await init(page)
43+
44+
const textarea = page.locator('textarea')
45+
const input = page.locator('input')
46+
input.evaluate((el: HTMLInputElement) => el.type = 'password')
47+
await page.evaluate(() => {
48+
window.fcitx.setInputMethods(['keyboard-us', 'keyboard-th'])
49+
window.fcitx.setCurrentInputMethod('keyboard-th')
50+
})
51+
52+
await input.click()
53+
await page.keyboard.press('l')
54+
await expect(input).toHaveValue('l')
55+
56+
await textarea.click()
57+
await page.keyboard.press('l')
58+
await expect(textarea).toHaveValue('ส')
59+
})

wasmfrontend/wasmfrontend.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ WasmFrontend::WasmFrontend(Instance *instance)
1414
// Make mostRecentInputContext not null so that current IM info can be
1515
// retrieved on load finish, even if no DOM element can be actually focused
1616
// (e.g. when focusing on address bar).
17-
focusIn();
17+
focusIn(false);
1818
}
1919

2020
void WasmFrontend::createInputContext() {
@@ -28,7 +28,14 @@ bool WasmFrontend::keyEvent(const Key &key, bool isRelease) {
2828
return event.accepted();
2929
}
3030

31-
void WasmFrontend::focusIn() { ic_->focusIn(); }
31+
void WasmFrontend::focusIn(bool isPassword) {
32+
CapabilityFlags flags = CapabilityFlag::Preedit;
33+
if (isPassword) {
34+
flags |= CapabilityFlag::Password;
35+
}
36+
ic_->setCapabilityFlags(flags);
37+
ic_->focusIn();
38+
}
3239

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

@@ -37,8 +44,6 @@ void WasmFrontend::resetInput() { ic_->reset(); }
3744
WasmInputContext::WasmInputContext(WasmFrontend *frontend,
3845
InputContextManager &inputContextManager)
3946
: InputContext(inputContextManager, ""), frontend_(frontend) {
40-
CapabilityFlags flags = CapabilityFlag::Preedit;
41-
setCapabilityFlags(flags);
4247
created();
4348
}
4449

wasmfrontend/wasmfrontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class WasmFrontend : public AddonInstance {
2323

2424
void createInputContext();
2525
bool keyEvent(const Key &key, bool isRelease);
26-
void focusIn();
26+
void focusIn(bool isPassword);
2727
void focusOut();
2828
void resetInput();
2929

0 commit comments

Comments
 (0)