From 4cb4de265669dc312206ccda906d166443457700 Mon Sep 17 00:00:00 2001 From: Bibhav Adhikari Date: Sat, 13 Jun 2026 07:24:41 -0500 Subject: [PATCH] gh-8391: Prevent opening glance when selecting text in link (gh-14164) --- src/zen/glance/actors/ZenGlanceChild.sys.mjs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/zen/glance/actors/ZenGlanceChild.sys.mjs b/src/zen/glance/actors/ZenGlanceChild.sys.mjs index 10d9fff14..f31b83e61 100644 --- a/src/zen/glance/actors/ZenGlanceChild.sys.mjs +++ b/src/zen/glance/actors/ZenGlanceChild.sys.mjs @@ -17,8 +17,14 @@ XPCOMUtils.defineLazyPreferenceGetter( true ); +// A small threshold to allow for minor mouse jitter during a normal click. +// Anything beyond this is likely an intentional drag (like selecting text). +const CLICK_DRAG_THRESHOLD_PX = 4; + export class ZenGlanceChild extends JSWindowActorChild { #activationMethod; + #mouseDownX = null; + #mouseDownY = null; constructor() { super(); @@ -121,9 +127,23 @@ export class ZenGlanceChild extends JSWindowActorChild { // The problem is that at that stage we don't know the rect or even what // element has been clicked, so we send the data here. this.#sendClickDataToParent(node, event.target); + + this.#mouseDownX = event.clientX; + this.#mouseDownY = event.clientY; } on_click(event) { + // If the user drags to select text inside a link, we shouldn't open glance. + if (this.#mouseDownX !== null && this.#mouseDownY !== null) { + const deltaX = Math.abs(event.clientX - this.#mouseDownX); + const deltaY = Math.abs(event.clientY - this.#mouseDownY); + this.#mouseDownX = null; + this.#mouseDownY = null; + if (deltaX > CLICK_DRAG_THRESHOLD_PX || deltaY > CLICK_DRAG_THRESHOLD_PX) { + return; + } + } + const { node, href, principal } = this.#getTargetFromEvent(event); if ( event.button !== 0 ||