From 795d15fa503fdc239aa4188f5e2ce44ec275dc91 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 22 Jan 2018 18:13:07 +0100 Subject: [PATCH] Update default `add` and `remove` listeners in UndoManager --- src/undo_manager/index.js | 22 ++++++++++++++++++++++ src/utils/Sorter.js | 12 +++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/undo_manager/index.js b/src/undo_manager/index.js index ae38cb9194..ce894ab639 100644 --- a/src/undo_manager/index.js +++ b/src/undo_manager/index.js @@ -30,6 +30,28 @@ module.exports = () => { this.em = em; um = new UndoManager({ track: true, register: [] }); um.changeUndoType('change', { condition: false }); + um.changeUndoType('add', { + on(model, collection, options = {}) { + if (options.avoidStore) return; + return { + object: collection, + before: undefined, + after: model, + options: { ...options } + }; + } + }); + um.changeUndoType('remove', { + on(model, collection, options = {}) { + if (options.avoidStore) return; + return { + object: collection, + before: model, + after: undefined, + options: { ...options } + }; + } + }); const customUndoType = { on(object, value, opt = {}) { !beforeCache && (beforeCache = object.previousAttributes()); diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index 295d27b770..7e1ad0fcd1 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -311,12 +311,14 @@ module.exports = Backbone.View.extend({ if (dropContent && em) { if (!dropModel) { let comps = em.get('DomComponents').getComponents(); - let tempModel = comps.add(dropContent, { + const opts = { + avoidStore: 1, avoidChildren: 1, avoidUpdateStyle: 1, temporary: 1 - }); - dropModel = comps.remove(tempModel, { temporary: 1 }); + }; + let tempModel = comps.add(dropContent, opts); + dropModel = comps.remove(tempModel, opts); this.dropModel = dropModel instanceof Array ? dropModel[0] : dropModel; } return dropModel; @@ -972,7 +974,7 @@ module.exports = Backbone.View.extend({ var opts = { at: index, noIncrement: 1 }; if (!dropContent) { - modelTemp = targetCollection.add({}, opts); + modelTemp = targetCollection.add({}, { ...opts, avoidStore: 1 }); if (model) { modelToDrop = model.collection.remove(model); @@ -986,7 +988,7 @@ module.exports = Backbone.View.extend({ created = targetCollection.add(modelToDrop, opts); if (!dropContent) { - targetCollection.remove(modelTemp); + targetCollection.remove(modelTemp, { avoidStore: 1 }); } else { this.dropContent = null; }