mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-09 16:19:25 -07:00
Cancel stale lookup scan fallback timer when closing popup
The setTimeout fallback in triggerLookupForSelectedWord was not being tracked or cancelled, causing it to fire after test globals were restored and hit an undefined document reference.
This commit is contained in:
@@ -38,6 +38,7 @@ export function createKeyboardHandlers(
|
|||||||
let pendingSelectionAnchorAfterSubtitleSeek: 'start' | 'end' | null = null;
|
let pendingSelectionAnchorAfterSubtitleSeek: 'start' | 'end' | null = null;
|
||||||
let pendingLookupRefreshAfterSubtitleSeek = false;
|
let pendingLookupRefreshAfterSubtitleSeek = false;
|
||||||
let resetSelectionToStartOnNextSubtitleSync = false;
|
let resetSelectionToStartOnNextSubtitleSync = false;
|
||||||
|
let lookupScanFallbackTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
const CHORD_MAP = new Map<
|
const CHORD_MAP = new Map<
|
||||||
string,
|
string,
|
||||||
@@ -483,7 +484,9 @@ export function createKeyboardHandlers(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Fallback only if the explicit scan path did not open popup quickly.
|
// Fallback only if the explicit scan path did not open popup quickly.
|
||||||
setTimeout(() => {
|
if (lookupScanFallbackTimer !== null) clearTimeout(lookupScanFallbackTimer);
|
||||||
|
lookupScanFallbackTimer = setTimeout(() => {
|
||||||
|
lookupScanFallbackTimer = null;
|
||||||
if (ctx.state.yomitanPopupVisible || isYomitanPopupVisible(document)) {
|
if (ctx.state.yomitanPopupVisible || isYomitanPopupVisible(document)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -523,6 +526,10 @@ export function createKeyboardHandlers(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lookupScanFallbackTimer !== null) {
|
||||||
|
clearTimeout(lookupScanFallbackTimer);
|
||||||
|
lookupScanFallbackTimer = null;
|
||||||
|
}
|
||||||
dispatchYomitanPopupVisibility(false);
|
dispatchYomitanPopupVisibility(false);
|
||||||
dispatchYomitanFrontendClearActiveTextSource();
|
dispatchYomitanFrontendClearActiveTextSource();
|
||||||
clearNativeSubtitleSelection();
|
clearNativeSubtitleSelection();
|
||||||
|
|||||||
Reference in New Issue
Block a user