mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-09-07 20:43:00 -07:00
- Support multi-row selection with clean clipboard text - Preserve selections across playback updates and clear them on source changes
89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
export type OverlayWindowKind = 'visible' | 'modal';
|
|
|
|
export function isTabInputForMpvForwarding(input: Electron.Input): boolean {
|
|
if (input.type !== 'keyDown' || input.isAutoRepeat) return false;
|
|
if (input.alt || input.control || input.meta || input.shift) return false;
|
|
return input.code === 'Tab' || input.key === 'Tab';
|
|
}
|
|
|
|
function isLookupWindowToggleInput(input: Electron.Input): boolean {
|
|
if (input.type !== 'keyDown') return false;
|
|
if (input.alt) return false;
|
|
if (!input.control && !input.meta) return false;
|
|
if (input.shift) return false;
|
|
const normalizedKey = typeof input.key === 'string' ? input.key.toLowerCase() : '';
|
|
return input.code === 'KeyY' || normalizedKey === 'y';
|
|
}
|
|
|
|
function isKeyboardModeToggleInput(input: Electron.Input): boolean {
|
|
if (input.type !== 'keyDown') return false;
|
|
if (input.alt) return false;
|
|
if (!input.control && !input.meta) return false;
|
|
if (!input.shift) return false;
|
|
const normalizedKey = typeof input.key === 'string' ? input.key.toLowerCase() : '';
|
|
return input.code === 'KeyY' || normalizedKey === 'y';
|
|
}
|
|
|
|
export function handleOverlayWindowBeforeInputEvent(options: {
|
|
kind: OverlayWindowKind;
|
|
windowVisible: boolean;
|
|
input: Electron.Input;
|
|
preventDefault: () => void;
|
|
sendKeyboardModeToggleRequested: () => void;
|
|
sendLookupWindowToggleRequested: () => void;
|
|
tryHandleOverlayShortcutLocalFallback: (input: Electron.Input) => boolean;
|
|
forwardTabToMpv: () => void;
|
|
}): boolean {
|
|
if (options.kind === 'modal') return false;
|
|
if (!options.windowVisible) return false;
|
|
|
|
// The renderer decides whether Copy targets selected sidebar text or the live cue.
|
|
if (
|
|
(options.input.control || options.input.meta) &&
|
|
!options.input.alt &&
|
|
!options.input.shift &&
|
|
(options.input.code === 'KeyC' || options.input.key.toLowerCase() === 'c')
|
|
)
|
|
return false;
|
|
|
|
if (isKeyboardModeToggleInput(options.input)) {
|
|
options.preventDefault();
|
|
options.sendKeyboardModeToggleRequested();
|
|
return true;
|
|
}
|
|
|
|
if (isLookupWindowToggleInput(options.input)) {
|
|
options.preventDefault();
|
|
options.sendLookupWindowToggleRequested();
|
|
return true;
|
|
}
|
|
|
|
if (isTabInputForMpvForwarding(options.input)) {
|
|
options.preventDefault();
|
|
options.forwardTabToMpv();
|
|
return true;
|
|
}
|
|
|
|
if (!options.tryHandleOverlayShortcutLocalFallback(options.input)) return false;
|
|
options.preventDefault();
|
|
return true;
|
|
}
|
|
|
|
export function handleOverlayWindowBlurred(options: {
|
|
kind: OverlayWindowKind;
|
|
windowVisible: boolean;
|
|
isOverlayVisible: (kind: OverlayWindowKind) => boolean;
|
|
ensureOverlayWindowLevel: () => void;
|
|
moveWindowTop: () => void;
|
|
onVisibleOverlayBlur?: () => void;
|
|
platform?: NodeJS.Platform;
|
|
}): boolean {
|
|
if (options.kind === 'visible') {
|
|
options.onVisibleOverlayBlur?.();
|
|
return false;
|
|
}
|
|
|
|
options.ensureOverlayWindowLevel();
|
|
return true;
|
|
}
|