From 0fe4008d1121720f735ce314d60ce7f404b8003d Mon Sep 17 00:00:00 2001 From: Zhigang Zhang Date: Mon, 16 Oct 2023 14:19:52 +0800 Subject: [PATCH] fix bug: draggable-node plugin block dblclick to trigger the edit mode (#511) --- src/plugins/jsmind.draggable-node.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/plugins/jsmind.draggable-node.js b/src/plugins/jsmind.draggable-node.js index 0714a582..1bb164fd 100644 --- a/src/plugins/jsmind.draggable-node.js +++ b/src/plugins/jsmind.draggable-node.js @@ -26,6 +26,7 @@ const clear_selection = const DEFAULT_OPTIONS = { line_width: 5, line_color: 'rgba(0,0,0,0.3)', + drag_start_delay: 100, lookup_delay: 500, lookup_interval: 80, scrolling_trigger_width: 20, @@ -55,6 +56,7 @@ class DraggableNode { this.offset_y = 0; this.hlookup_delay = 0; this.hlookup_timer = 0; + this.hdrag_start_delay = 0; this.capture = false; this.moved = false; this.canvas_draggable = jm.get_view_draggable(); @@ -206,7 +208,10 @@ class DraggableNode { var container = this.jm.view.container; $.on(container, 'mousedown', function (e) { var evt = e || event; - jd.dragstart.call(jd, evt); + jd.hdrag_start_delay = $.w.setTimeout(function () { + jd.hdrag_start_delay = 0; + jd.dragstart.call(jd, evt); + }, jd.options.drag_start_delay); }); $.on(container, 'mousemove', function (e) { var evt = e || event; @@ -214,11 +219,18 @@ class DraggableNode { }); $.on(container, 'mouseup', function (e) { var evt = e || event; + if (jd.hdrag_start_delay != 0) { + $.w.clearTimeout(jd.hdrag_start_delay); + jd.hdrag_start_delay = 0; + } jd.dragend.call(jd, evt); }); $.on(container, 'touchstart', function (e) { var evt = e || event; - jd.dragstart.call(jd, evt); + jd.hdrag_start_delay = $.w.setTimeout(function () { + jd.hdrag_start_delay = 0; + jd.dragstart.call(jd, evt); + }, jd.options.drag_start_delay); }); $.on(container, 'touchmove', function (e) { var evt = e || event; @@ -226,6 +238,10 @@ class DraggableNode { }); $.on(container, 'touchend', function (e) { var evt = e || event; + if (jd.hdrag_start_delay != 0) { + $.w.clearTimeout(jd.hdrag_start_delay); + jd.hdrag_start_delay = 0; + } jd.dragend.call(jd, evt); }); } @@ -273,9 +289,7 @@ class DraggableNode { jd.lookup_close_node.call(jd); }, jd.options.lookup_interval); }, this.options.lookup_delay); - $.w.setTimeout(function () { - jd.capture = true; - }, 0); + jd.capture = true; } } }