From 893eead7181a8f84b7defe32f1a1d19d71094f79 Mon Sep 17 00:00:00 2001 From: "mr. M" Date: Tue, 29 Oct 2024 09:51:35 +0100 Subject: [PATCH] Refactor ZenGlanceChild.sys.mjs to use 'mantain' as the activation method instead of 'hover' --- src/actors/ZenGlanceChild.sys.mjs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/actors/ZenGlanceChild.sys.mjs b/src/actors/ZenGlanceChild.sys.mjs index ba84bff..ea49de9 100644 --- a/src/actors/ZenGlanceChild.sys.mjs +++ b/src/actors/ZenGlanceChild.sys.mjs @@ -38,7 +38,7 @@ export class ZenGlanceChild extends JSWindowActorChild { async initiateGlance() { this.mouseIsDown = false; const activationMethod = await this.getActivationMethod(); - if (activationMethod === 'hover') { + if (activationMethod === 'mantain') { this.contentWindow.addEventListener('mousedown', this.mouseDownListener); this.contentWindow.addEventListener('mouseup', this.mouseUpListener); @@ -67,18 +67,26 @@ export class ZenGlanceChild extends JSWindowActorChild { } handleMouseUp(event) { - this.mouseIsDown = false; + if (this.hasClicked) { + event.preventDefault(); + event.stopPropagation(); + this.hasClicked = false; + } + this.mouseIsDown = null; } async handleMouseDown(event) { - if (event.target.tagName !== 'A') { + const target = event.target.closest('A'); + console.log('target', target); + if (!target) { return; } - this.mouseIsDown = true; + this.mouseIsDown = target; const hoverActivationDelay = await this.getHoverActivationDelay(); - setTimeout(() => { - if (this.mouseIsDown) { - this.openGlance(event.target); + this.contentWindow.setTimeout(() => { + if (this.mouseIsDown === target) { + this.hasClicked = true; + this.openGlance(target); } }, hoverActivationDelay); } @@ -94,7 +102,7 @@ export class ZenGlanceChild extends JSWindowActorChild { return; } else if (activationMethod === 'shift' && !event.shiftKey) { return; - } else if (activationMethod === 'hover' || typeof activationMethod === 'undefined') { + } else if (activationMethod === 'mantain' || typeof activationMethod === 'undefined') { return; } // get closest A element