From 31a8dfa09a91269d781a6c847dd4241b3ec1d5cc Mon Sep 17 00:00:00 2001 From: Roman Bruckner Date: Mon, 28 Mar 2022 08:50:23 +0200 Subject: [PATCH] dia.Paper: make sure paper:mouseenter event is always triggered (#1639) --- src/dia/Paper.mjs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/dia/Paper.mjs b/src/dia/Paper.mjs index 0cf2a3c20..5843e1552 100644 --- a/src/dia/Paper.mjs +++ b/src/dia/Paper.mjs @@ -2136,18 +2136,32 @@ export const Paper = View.extend({ evt = normalizeEvent(evt); - var view = this.findView(evt.target); + const { + target, // The EventTarget the pointing device entered to + relatedTarget // The EventTarget the pointing device exited from + } = evt; + const view = this.findView(target); if (this.guard(evt, view)) return; - var relatedView = this.findView(evt.relatedTarget); + const relatedView = this.findView(relatedTarget); if (view) { - // mouse moved from tool over view? - if (relatedView === view) return; + if (relatedView === view) { + // Mouse left a cell tool + return; + } + // prevent double `mouseenter` event if the `relatedTarget` is outside the paper + // (mouseenter method would be fired twice) + evt.stopPropagation(); view.mouseenter(evt); - } else { - if (relatedView) return; - // `paper` (more descriptive), not `blank` - this.trigger('paper:mouseenter', evt); + if (this.el.contains(relatedTarget)) { + // The pointer remains inside the paper. + return; + } + } + if (relatedView) { + return; } + // `paper` (more descriptive), not `blank` + this.trigger('paper:mouseenter', evt); }, mouseleave: function(evt) {