From 7ede2e805459f914bb5ba704978eaba11ef9bb09 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Mon, 2 Nov 2020 21:56:42 +0100 Subject: [PATCH] Fix drag and drop of items --- list-editor/index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/list-editor/index.js b/list-editor/index.js index c130e71..15d54d3 100644 --- a/list-editor/index.js +++ b/list-editor/index.js @@ -364,21 +364,26 @@ function editor(root, inputData, options) { }) drake.on('drop', function (el, target, source, sibling) { + let wasEditing = editing + stopEditing(root, store, currentEditor) + let stopID = $(sibling).attr('data-id') if (startID === stopID) { return } - let id = store.moveBefore(startID, stopID) - if (id === startID) { - return - } + let newPosition = store.moveBefore(startID, stopID) + cursor.set(newPosition) - let position = store.index(id); - cursor.set(position) + _.defer(() => { + trigger('change') + + if (wasEditing) { + startEditing(root, store, cursor); + } + }) - trigger('change') }) return drake; } @@ -401,11 +406,6 @@ function editor(root, inputData, options) { }) }) - if (store.hasChanged()) { - trigger('change') - store.clearChanged() - } - let $span = $('
'); options.transform(text, $span, id, EDITOR) element.replaceWith($span);