fix: allow selection within link, b=closes https://github.com/zen-browser/desktop/issues/8391, p=#11394

* fix: allow selection within link

fixes: #8391

The glance feature was clashing with the possibility to select text within a link.
To avoid the conflict, glance will only open upon mouseup and only if the mouse hasn't moved since the mouse was pressed.

* remove redundant condition

* register listeners in correct place

* feat: Listen to mouse move only once, b=no-bug, c=common, glance

---------

Co-authored-by: mr. m <mr.m@tuta.com>
This commit is contained in:
Lukas Spiss
2025-11-23 11:58:07 +00:00
committed by GitHub
parent 894fce098f
commit 8612e0d1e9
2 changed files with 19 additions and 2 deletions

View File

@@ -45,6 +45,9 @@ let JSWINDOWACTORS = {
mousedown: {
capture: true,
},
mouseup: {
capture: true,
},
keydown: {
capture: true,
},

View File

@@ -3,9 +3,11 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
export class ZenGlanceChild extends JSWindowActorChild {
#activationMethod;
#glanceTarget = null;
constructor() {
super();
this.mousemoveCallback = this.mousemoveCallback.bind(this);
}
async handleEvent(event) {
@@ -80,11 +82,23 @@ export class ZenGlanceChild extends JSWindowActorChild {
} else if (activationMethod === 'meta' && !event.metaKey) {
return;
}
if (target) {
this.#glanceTarget = target;
window.addEventListener('mousemove', this.mousemoveCallback, { once: true });
}
on_mouseup(event) {
if (this.#glanceTarget) {
event.preventDefault();
event.stopPropagation();
this.#openGlance(this.#glanceTarget);
this.#glanceTarget = null;
window.removeEventListener('mousemove', this.mousemoveCallback);
}
}
this.#openGlance(target);
mousemoveCallback() {
if (this.#glanceTarget) {
this.#glanceTarget = null;
}
}