Skip to content

Commit

Permalink
reset layout on hide
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Mar 1, 2025
1 parent a7f51b9 commit c558def
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface SystemEvent {
export type SystemEvent = {
type: 'ENTER_KEY_TYPE'
data: string
} | {
type: 'HIDE'
}

export interface VirtualKeyboardEvent {
Expand Down
5 changes: 4 additions & 1 deletion src/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import presetCss from 'bundle-text:./preset.css'
import qwerty from '../layouts/qwerty.json'
import { renderRow } from './key'
import { div } from './util'
import { onTouchEnd, onTouchStart, setEnterKeyType, setLayout as setLayout_ } from './ux'
import { onTouchEnd, onTouchStart, setEnterKeyType, setLayer, setLayout as setLayout_ } from './ux'

const builtInLayoutMap = { qwerty } as { [key: string]: Layout }

Expand Down Expand Up @@ -56,5 +56,8 @@ export function onMessage(message: string) {
case 'ENTER_KEY_TYPE':
setEnterKeyType(event.data)
break
case 'HIDE':
setLayer('default', false)
break
}
}
12 changes: 12 additions & 0 deletions tests/test-generic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ test('Preserve press order', async ({ page }) => {
await expect(w).toHaveCSS('background-color', WHITE)
await expect(o).toHaveCSS('background-color', WHITE)
})

test('HIDE event', async ({ page }) => {
await init(page)

const q = page.getByText('q')
const shift = page.locator('.fcitx-keyboard-shift')
await tap(shift)
await expect(q).toHaveText('Q')

await sendSystemEvent(page, { type: 'HIDE' })
await expect(q).toHaveText('q')
})

0 comments on commit c558def

Please sign in to comment.