Skip to content

Commit 8612e0d

Browse files
Spissablemr-cheffy
andauthored
fix: allow selection within link, b=closes #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 <[email protected]>
1 parent 894fce0 commit 8612e0d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/zen/common/sys/ZenActorsManager.sys.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ let JSWINDOWACTORS = {
4545
mousedown: {
4646
capture: true,
4747
},
48+
mouseup: {
49+
capture: true,
50+
},
4851
keydown: {
4952
capture: true,
5053
},

src/zen/glance/actors/ZenGlanceChild.sys.mjs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
export class ZenGlanceChild extends JSWindowActorChild {
55
#activationMethod;
6+
#glanceTarget = null;
67

78
constructor() {
89
super();
10+
this.mousemoveCallback = this.mousemoveCallback.bind(this);
911
}
1012

1113
async handleEvent(event) {
@@ -80,11 +82,23 @@ export class ZenGlanceChild extends JSWindowActorChild {
8082
} else if (activationMethod === 'meta' && !event.metaKey) {
8183
return;
8284
}
83-
if (target) {
85+
this.#glanceTarget = target;
86+
window.addEventListener('mousemove', this.mousemoveCallback, { once: true });
87+
}
88+
89+
on_mouseup(event) {
90+
if (this.#glanceTarget) {
8491
event.preventDefault();
8592
event.stopPropagation();
93+
this.#openGlance(this.#glanceTarget);
94+
this.#glanceTarget = null;
95+
window.removeEventListener('mousemove', this.mousemoveCallback);
96+
}
97+
}
8698

87-
this.#openGlance(target);
99+
mousemoveCallback() {
100+
if (this.#glanceTarget) {
101+
this.#glanceTarget = null;
88102
}
89103
}
90104

0 commit comments

Comments
 (0)