fix: support repeated popup scroll keys

This commit is contained in:
2026-03-05 19:20:55 -08:00
parent 0cac446725
commit 8ca05859a9
3 changed files with 46 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ type CommandEventDetail = {
visible?: boolean;
key?: string;
code?: string;
repeat?: boolean;
};
function createClassList() {
@@ -375,6 +376,36 @@ test('keyboard mode: up/down/j/k forward keydown to yomitan popup when open', as
}
});
test('keyboard mode: repeated popup navigation keys are forwarded while popup is open', async () => {
const { ctx, handlers, testGlobals } = createKeyboardHandlerHarness();
try {
await handlers.setupMpvInputForwarding();
handlers.handleKeyboardModeToggleRequested();
ctx.state.yomitanPopupVisible = true;
testGlobals.setPopupVisible(true);
testGlobals.dispatchKeydown({ key: 'j', code: 'KeyJ', repeat: true });
testGlobals.dispatchKeydown({ key: 'ArrowDown', code: 'ArrowDown', repeat: true });
const forwarded = testGlobals.commandEvents.filter(
(event) => event.type === 'forwardKeyDown',
);
assert.equal(forwarded.length, 2);
assert.deepEqual(
forwarded.map((event) => ({ code: event.code, repeat: event.repeat })),
[
{ code: 'KeyJ', repeat: true },
{ code: 'ArrowDown', repeat: true },
],
);
} finally {
ctx.state.keyboardDrivenModeEnabled = false;
testGlobals.restore();
}
});
test('keyboard mode: h moves left when popup is closed', async () => {
const { ctx, handlers, testGlobals } = createKeyboardHandlerHarness();

View File

@@ -446,7 +446,6 @@ export function createKeyboardHandlers(
}
function handleYomitanPopupKeybind(e: KeyboardEvent): boolean {
if (e.repeat) return false;
const modifierOnlyCodes = new Set([
'ShiftLeft',
'ShiftRight',
@@ -460,6 +459,7 @@ export function createKeyboardHandlers(
if (modifierOnlyCodes.has(e.code)) return false;
if (!e.ctrlKey && !e.metaKey && !e.altKey && e.code === 'KeyM') {
if (e.repeat) return false;
dispatchYomitanPopupMineSelected();
return true;
}