Skip to content

Commit 499b8c7

Browse files
fix(desktop): voice controls answer the annotation overlay's redelivered clicks
Main's dictation buttons accept only trusted clicks and keep focus with a pointerdown preventDefault. The window-capture listener now stops both before they reach the closed shadow root, so mark redelivered clicks and apply the focus guard there. AI-assisted; verified with the tests and tools listed above.
1 parent ee479f7 commit 499b8c7

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

‎apps/desktop/src/preview/PickPreload.ts‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -711,12 +711,11 @@ function startAnnotation(
711711
voice.shortcuts.some((shortcut) =>
712712
matchesKeybindingShortcut(event, shortcut, navigator.platform),
713713
);
714-
for (const button of [voiceButton, voiceFinish, voiceCancel, voiceSkip]) {
715-
button.addEventListener("pointerdown", (event) => event.preventDefault());
716-
}
717-
// Page scripts cannot reach the closed shadow root, and a synthetic click never counts.
714+
const voiceControls = [voiceButton, voiceFinish, voiceCancel, voiceSkip];
715+
// Clicks the window listener redelivers from real input; page script cannot forge these.
716+
const overlayClicks = new WeakSet<Event>();
718717
voiceButton.addEventListener("click", (event) => {
719-
if (!event.isTrusted) return;
718+
if (!overlayClicks.has(event)) return;
720719
if (voiceSettings) {
721720
sendVoice("settings");
722721
return;
@@ -725,15 +724,15 @@ function startAnnotation(
725724
sendVoice(voicePhase === "recording" ? "stop" : "start");
726725
});
727726
voiceFinish.addEventListener("click", (event) => {
728-
if (event.isTrusted) sendVoice("stop");
727+
if (overlayClicks.has(event)) sendVoice("stop");
729728
});
730729
voiceCancel.addEventListener("click", (event) => {
731-
if (!event.isTrusted) return;
730+
if (!overlayClicks.has(event)) return;
732731
pendingVoiceSubmission = null;
733732
sendVoice("cancel");
734733
});
735734
voiceSkip.addEventListener("click", (event) => {
736-
if (event.isTrusted) sendVoice("skip");
735+
if (overlayClicks.has(event)) sendVoice("skip");
737736
});
738737
const onVoiceState = (
739738
_event: Electron.IpcRendererEvent,
@@ -1497,7 +1496,11 @@ function startAnnotation(
14971496
// Page script can dispatch on the host; only real input may reach the closed overlay.
14981497
if (!event.isTrusted) return;
14991498
pressTarget = shadowRoot.elementFromPoint(event.clientX, event.clientY);
1500-
if (pressTarget && dragHandle.contains(pressTarget)) onEditorPointerDown(event);
1499+
if (!pressTarget) return;
1500+
if (dragHandle.contains(pressTarget)) onEditorPointerDown(event);
1501+
// Voice controls keep focus in the comment field they dictate into.
1502+
else if (voiceControls.some((control) => control.contains(pressTarget)))
1503+
event.preventDefault();
15011504
return;
15021505
}
15031506
if (event.button !== 0) return;
@@ -1588,7 +1591,9 @@ function startAnnotation(
15881591
event.stopPropagation();
15891592
if (!event.isTrusted) return;
15901593
// The trusted click already ran native activation; a plain Event only reaches listeners.
1591-
overlayClickTarget(event)?.dispatchEvent(new Event("click", { bubbles: true }));
1594+
const click = new Event("click", { bubbles: true });
1595+
overlayClicks.add(click);
1596+
overlayClickTarget(event)?.dispatchEvent(click);
15921597
return;
15931598
}
15941599
event.preventDefault();

0 commit comments

Comments
 (0)