From a383deefc845b67aba236a0c12d7ceb13509adf4 Mon Sep 17 00:00:00 2001 From: Roman Bruckner Date: Tue, 23 Apr 2024 21:57:01 +0800 Subject: [PATCH] fix(linkTools.Arrowhead): fix to trigger missing paper pointerdown event (#2625) --- .../joint-core/src/linkTools/Arrowhead.mjs | 4 +- .../joint-core/test/jointjs/dia/linkTools.js | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/joint-core/src/linkTools/Arrowhead.mjs b/packages/joint-core/src/linkTools/Arrowhead.mjs index 7ce59e12b..afcc1be39 100644 --- a/packages/joint-core/src/linkTools/Arrowhead.mjs +++ b/packages/joint-core/src/linkTools/Arrowhead.mjs @@ -48,12 +48,14 @@ const Arrowhead = ToolView.extend({ evt.stopPropagation(); evt.preventDefault(); var relatedView = this.relatedView; + var paper = relatedView.paper; relatedView.model.startBatch('arrowhead-move', { ui: true, tool: this.cid }); relatedView.startArrowheadMove(this.arrowheadType); this.delegateDocumentEvents(); - relatedView.paper.undelegateEvents(); + paper.undelegateEvents(); this.focus(); this.el.style.pointerEvents = 'none'; + relatedView.notifyPointerdown(...paper.getPointerArgs(evt)); }, onPointerMove: function(evt) { var normalizedEvent = util.normalizeEvent(evt); diff --git a/packages/joint-core/test/jointjs/dia/linkTools.js b/packages/joint-core/test/jointjs/dia/linkTools.js index 939f0bb1c..be5f2775e 100644 --- a/packages/joint-core/test/jointjs/dia/linkTools.js +++ b/packages/joint-core/test/jointjs/dia/linkTools.js @@ -304,6 +304,43 @@ QUnit.module('linkTools', function(hooks) { }); }); + QUnit.module('TargetArrowhead', function() { + QUnit.test('events', function(assert) { + + const arrowhead = new joint.linkTools.TargetArrowhead(); + linkView.addTools(new joint.dia.ToolsView({ tools: [arrowhead] })); + const listener = new joint.mvc.Listener(); + const events = []; + + listener.listenTo(paper, { + 'all': (eventName) => events.push(eventName) + }); + + // Make sure the link is connected to a target element + assert.ok(link.getTargetCell()); + + simulate.mousedown({ el: arrowhead.el }); + simulate.mousemove({ el: paper.el }); + simulate.mouseup({ el: paper.el }); + + assert.deepEqual( + events.filter((event) => event !== 'render:done'), + [ + 'cell:pointerdown', + 'link:pointerdown', + 'cell:pointermove', + 'link:pointermove', + 'link:disconnect', + 'link:pointerup', + 'cell:pointerup', + 'cell:mouseleave', + 'link:mouseleave', + ] + ); + + listener.stopListening(); + }); + }); });