Skip to content

Commit 42bbbbc

Browse files
authored
caret blink on keyboard (#45)
1 parent 3aed611 commit 42bbbbc

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

page/caret.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let show = false
1313
export function removeCaret() {
1414
if (timer) {
1515
window.clearInterval(timer)
16+
timer = null
1617
}
1718
document.querySelectorAll('.fcitx-mobile-caret').forEach(div => div.remove())
1819
}

tests/test-caret.mobile.spec.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ test('Touch', async ({ page }) => {
4343
const caret = page.locator('.fcitx-mobile-caret')
4444
const { x: x0 } = await getBox(caret)
4545

46-
await tapKeyboard(page, 'a@')
47-
await textarea.evaluate((el: HTMLTextAreaElement) => el.selectionStart = el.selectionEnd = 0)
46+
await textarea.evaluate((el: HTMLTextAreaElement) => {
47+
el.value = 'a'
48+
el.selectionStart = el.selectionEnd = 0
49+
})
4850
const { x } = await getBox(caret)
4951
expect(x).toEqual(x0)
5052

5153
await textarea.tap()
52-
const { x: x1 } = await getBox(caret)
53-
expect(x1, 'Tapping on center should effectively change caret position').toBeGreaterThan(x0)
54+
while (true) {
55+
const { x: x1 } = await getBox(caret)
56+
// Tapping on center should effectively change caret position
57+
if (x1 > x0) {
58+
break
59+
}
60+
}
5461
})

tests/util.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ export function browserName(page: Page) {
1212
return page.context().browser()!.browserType().name()
1313
}
1414

15-
export async function getBox(locator: Locator) {
16-
return (await locator.boundingBox())!
15+
export async function getBox(locator: Locator): Promise<{ x: number, y: number, width: number, height: number }> {
16+
while (true) {
17+
const box = await locator.boundingBox()
18+
if (box)
19+
return box
20+
}
1721
}
1822

1923
// For test, don't let the initial "en" tip on focus affect panel visibility.

webkeyboard/webkeyboard.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ void WebKeyboard::update(UserInterfaceComponent component,
2626
auto preedit =
2727
instance_->outputFilter(inputContext, inputPanel.preedit())
2828
.toString();
29-
notify_main_async(
30-
json{{"type", "PREEDIT"},
31-
{"data", {{"auxUp", auxUp}, {"preedit", preedit}}}}
32-
.dump());
29+
notify_main_async(json{{"type", "PREEDIT"},
30+
{"data",
31+
{{"auxUp", auxUp},
32+
{"preedit", preedit},
33+
{"caret", inputPanel.preedit().cursor()}}}}
34+
.dump());
3335
if (const auto &list = inputPanel.candidateList()) {
3436
const auto &bulk = list->toBulk();
3537
if (bulk) {

0 commit comments

Comments
 (0)