fix: accept modified digits for multi-line sentence mining

This commit is contained in:
2026-04-27 20:14:09 -07:00
parent 2fbc90cf3a
commit bacc90cd24
7 changed files with 259 additions and 11 deletions

View File

@@ -1168,6 +1168,32 @@ test('session binding: copy subtitle multiple captures follow-up digit locally',
}
});
test('session binding: mine sentence multiple captures modified follow-up digit locally', async () => {
const { handlers, testGlobals } = createKeyboardHandlerHarness();
try {
await handlers.setupMpvInputForwarding();
handlers.updateSessionBindings([
{
sourcePath: 'shortcuts.mineSentenceMultiple',
originalKey: 'Ctrl+Shift+S',
key: { code: 'KeyS', modifiers: ['ctrl', 'shift'] },
actionType: 'session-action',
actionId: 'mineSentenceMultiple',
},
] as never);
testGlobals.dispatchKeydown({ key: 'S', code: 'KeyS', ctrlKey: true, shiftKey: true });
testGlobals.dispatchKeydown({ key: '#', code: 'Digit3', ctrlKey: true, shiftKey: true });
assert.deepEqual(testGlobals.sessionActions, [
{ actionId: 'mineSentenceMultiple', payload: { count: 3 } },
]);
} finally {
testGlobals.restore();
}
});
test('keyboard mode: h moves left when popup is closed', async () => {
const { ctx, handlers, testGlobals } = createKeyboardHandlerHarness();

View File

@@ -176,13 +176,17 @@ export function createKeyboardHandlers(
return true;
}
if (!/^[1-9]$/.test(e.key) || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) {
const digit = /^[1-9]$/.test(e.key)
? e.key
: (e.code.match(/^(?:Digit|Numpad)([1-9])$/)?.[1] ?? null);
if (!digit) {
e.preventDefault();
return true;
}
e.preventDefault();
const count = Number(e.key);
const count = Number(digit);
const actionId = pendingNumericSelection.actionId;
cancelPendingNumericSelection(false);
void window.electronAPI.dispatchSessionAction(actionId, { count });