fix(popups): close the history and command popups on an outside click or after 15s idle
The popups are non-focusable, so nothing closed them except their own toggle, Esc or a selection, while they held Enter, arrows, Esc and 0-9 as global shortcuts. Typing "3" or Enter in another app inserted a history entry or switched the active command. A click outside the popup (converted from physical pixels to DIP) or 15s without a navigation key now dismisses it and releases the keys.
This commit is contained in:
parent
67cc920e06
commit
06365651fc
3 changed files with 126 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import {
|
|||
PopupNavigationController,
|
||||
POPUP_NAV_KEYS,
|
||||
HISTORY_INSERT_DELAY_MS,
|
||||
POPUP_IDLE_DISMISS_MS,
|
||||
type PopupKind,
|
||||
type PopupWindowPort,
|
||||
} from '../../../src/main/windows/popup-navigation'
|
||||
|
|
@ -160,3 +161,65 @@ describe('PopupNavigationController', () => {
|
|||
expect(warn).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('PopupNavigationController — 저절로 닫기', () => {
|
||||
function withTimers(): {
|
||||
controller: PopupNavigationController
|
||||
windows: Record<PopupKind, FakeWindow>
|
||||
shortcuts: ReturnType<typeof fakeShortcuts>
|
||||
timers: Array<{ fn: () => void; ms: number; active: boolean }>
|
||||
} {
|
||||
const windows = { history: fakeWindow(), command: fakeWindow() }
|
||||
const shortcuts = fakeShortcuts()
|
||||
const timers: Array<{ fn: () => void; ms: number; active: boolean }> = []
|
||||
const controller = new PopupNavigationController({
|
||||
windows,
|
||||
shortcuts,
|
||||
insertText: async () => undefined,
|
||||
applyCommandSelection: () => undefined,
|
||||
startTimer: (fn, ms) => {
|
||||
const timer = { fn, ms, active: true }
|
||||
timers.push(timer)
|
||||
return () => {
|
||||
timer.active = false
|
||||
}
|
||||
},
|
||||
})
|
||||
return { controller, windows, shortcuts, timers }
|
||||
}
|
||||
|
||||
it('키 입력 없이 시간이 지나면 팝업을 닫고 전역 키를 놓는다', () => {
|
||||
const { controller, windows, shortcuts, timers } = withTimers()
|
||||
controller.show('history')
|
||||
const idle = timers.filter((t) => t.active)
|
||||
expect(idle).toHaveLength(1)
|
||||
expect(idle[0]?.ms).toBe(POPUP_IDLE_DISMISS_MS)
|
||||
|
||||
idle[0]?.fn()
|
||||
|
||||
expect(windows.history.visible).toBe(false)
|
||||
expect(shortcuts.registered.size).toBe(0)
|
||||
})
|
||||
|
||||
it('키를 누르면 유휴 시간을 다시 잰다', () => {
|
||||
const { controller, shortcuts, timers } = withTimers()
|
||||
controller.show('history')
|
||||
shortcuts.press('Down')
|
||||
|
||||
expect(timers.filter((t) => t.active)).toHaveLength(1)
|
||||
expect(timers[0]?.active).toBe(false)
|
||||
})
|
||||
|
||||
it('팝업 바깥을 클릭하면 닫고, 안쪽 클릭은 그대로 둔다', () => {
|
||||
const { controller, windows, shortcuts } = withTimers()
|
||||
windows.history.containsPoint = (p) => p.x >= 100 && p.x <= 300 && p.y >= 100 && p.y <= 300
|
||||
controller.show('history')
|
||||
|
||||
controller.handlePointerDown({ x: 150, y: 150 })
|
||||
expect(windows.history.visible).toBe(true)
|
||||
|
||||
controller.handlePointerDown({ x: 900, y: 900 })
|
||||
expect(windows.history.visible).toBe(false)
|
||||
expect(shortcuts.registered.size).toBe(0)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue