mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-06 19:57:26 -08:00
fix: support repeated popup scroll keys
This commit is contained in:
@@ -10,6 +10,7 @@ type CommandEventDetail = {
|
|||||||
visible?: boolean;
|
visible?: boolean;
|
||||||
key?: string;
|
key?: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
|
repeat?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function createClassList() {
|
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 () => {
|
test('keyboard mode: h moves left when popup is closed', async () => {
|
||||||
const { ctx, handlers, testGlobals } = createKeyboardHandlerHarness();
|
const { ctx, handlers, testGlobals } = createKeyboardHandlerHarness();
|
||||||
|
|
||||||
|
|||||||
@@ -446,7 +446,6 @@ export function createKeyboardHandlers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleYomitanPopupKeybind(e: KeyboardEvent): boolean {
|
function handleYomitanPopupKeybind(e: KeyboardEvent): boolean {
|
||||||
if (e.repeat) return false;
|
|
||||||
const modifierOnlyCodes = new Set([
|
const modifierOnlyCodes = new Set([
|
||||||
'ShiftLeft',
|
'ShiftLeft',
|
||||||
'ShiftRight',
|
'ShiftRight',
|
||||||
@@ -460,6 +459,7 @@ export function createKeyboardHandlers(
|
|||||||
if (modifierOnlyCodes.has(e.code)) return false;
|
if (modifierOnlyCodes.has(e.code)) return false;
|
||||||
|
|
||||||
if (!e.ctrlKey && !e.metaKey && !e.altKey && e.code === 'KeyM') {
|
if (!e.ctrlKey && !e.metaKey && !e.altKey && e.code === 'KeyM') {
|
||||||
|
if (e.repeat) return false;
|
||||||
dispatchYomitanPopupMineSelected();
|
dispatchYomitanPopupMineSelected();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
17
vendor/yomitan/js/display/popup-main.js
vendored
17
vendor/yomitan/js/display/popup-main.js
vendored
@@ -48,7 +48,7 @@ await Application.main(true, async (application) => {
|
|||||||
displayResizer.prepare();
|
displayResizer.prepare();
|
||||||
|
|
||||||
document.addEventListener('keydown', (event) => {
|
document.addEventListener('keydown', (event) => {
|
||||||
if (event.defaultPrevented || event.repeat) { return; }
|
if (event.defaultPrevented) { return; }
|
||||||
if (event.ctrlKey || event.metaKey || event.altKey) { return; }
|
if (event.ctrlKey || event.metaKey || event.altKey) { return; }
|
||||||
|
|
||||||
const target = /** @type {?Element} */ (event.target instanceof Element ? event.target : null);
|
const target = /** @type {?Element} */ (event.target instanceof Element ? event.target : null);
|
||||||
@@ -59,29 +59,40 @@ await Application.main(true, async (application) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const code = event.code;
|
const code = event.code;
|
||||||
if (code === 'KeyJ' || code === 'KeyK') {
|
const isPopupScrollKey =
|
||||||
|
code === 'KeyJ' ||
|
||||||
|
code === 'KeyK' ||
|
||||||
|
code === 'ArrowDown' ||
|
||||||
|
code === 'ArrowUp';
|
||||||
|
if (isPopupScrollKey) {
|
||||||
const scanningOptions = display.getOptions()?.scanning;
|
const scanningOptions = display.getOptions()?.scanning;
|
||||||
const scale = Number.isFinite(scanningOptions?.reducedMotionScrollingScale)
|
const scale = Number.isFinite(scanningOptions?.reducedMotionScrollingScale)
|
||||||
? scanningOptions.reducedMotionScrollingScale
|
? scanningOptions.reducedMotionScrollingScale
|
||||||
: 1;
|
: 1;
|
||||||
display._scrollByPopupHeight(code === 'KeyJ' ? 1 : -1, scale);
|
display._scrollByPopupHeight(
|
||||||
|
code === 'KeyJ' || code === 'ArrowDown' ? 1 : -1,
|
||||||
|
scale,
|
||||||
|
);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code === 'KeyM') {
|
if (code === 'KeyM') {
|
||||||
|
if (event.repeat) { return; }
|
||||||
displayAnki._hotkeySaveAnkiNoteForSelectedEntry('0');
|
displayAnki._hotkeySaveAnkiNoteForSelectedEntry('0');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code === 'KeyP') {
|
if (code === 'KeyP') {
|
||||||
|
if (event.repeat) { return; }
|
||||||
void displayAudio.playAudio(display.selectedIndex, 0);
|
void displayAudio.playAudio(display.selectedIndex, 0);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code === 'BracketLeft' || code === 'BracketRight') {
|
if (code === 'BracketLeft' || code === 'BracketRight') {
|
||||||
|
if (event.repeat) { return; }
|
||||||
displayAudio._onMessageCycleAudioSource({direction: code === 'BracketLeft' ? 1 : -1});
|
displayAudio._onMessageCycleAudioSource({direction: code === 'BracketLeft' ? 1 : -1});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user