From a5ce4d8f05ffc8aaf36c877262b9cc8e9463ac37 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 10 Nov 2017 00:36:09 +0100 Subject: [PATCH] Don't allow dragging into itself (Fixes #583) --- app/ui/containers/app.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/ui/containers/app.js b/app/ui/containers/app.js index 87d95c157..0c26d5247 100644 --- a/app/ui/containers/app.js +++ b/app/ui/containers/app.js @@ -937,11 +937,20 @@ function mapDispatchToProps (dispatch) { } async function _moveDoc (docToMove, parentId, targetId, targetOffset) { + // Nothing to do. We are in the same spot as we started if (docToMove._id === targetId) { - // Nothing to do. We are in the same spot as we started return; } + // Don't allow dragging things into itself or children. This will disconnect + // the node from the tree and cause the item to no longer show in the UI. + const descendents = await db.withDescendants(docToMove); + for (const doc of descendents) { + if (doc._id === parentId) { + return; + } + } + function __updateDoc (doc, patch) { models.getModel(docToMove.type).update(doc, patch); }