From c7ff050a99a6ac56c6945c573eb8e3953e70c029 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 11 Dec 2017 01:58:18 +0100 Subject: [PATCH] Start tracking rules in undo manager --- src/css_composer/index.js | 22 +++++++++++++++++++++- src/editor/model/Editor.js | 6 +++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/css_composer/index.js b/src/css_composer/index.js index d3cc7aa4a..20b4e3304 100644 --- a/src/css_composer/index.js +++ b/src/css_composer/index.js @@ -91,15 +91,35 @@ module.exports = () => { rules.add(c.rules); }, + /** * Do stuff after load * @param {Editor} em * @private */ postLoad(em) { - em.listenRules(this.getAll()); + const ev = 'add remove'; + const rules = this.getAll(); + const um = em.get('UndoManager'); + um && um.add(rules); + em.stopListening(rules, ev, this.handleChange); + em.listenTo(rules, ev, this.handleChange); + rules.each(rule => this.handleChange(rule)); + }, + + + /** + * Handle rule changes + * @private + */ + handleChange(model) { + const ev = 'change:style'; + const handleUpdates = em.handleUpdates.bind(em); + em.stopListening(model, ev, handleUpdates); + em.listenTo(model, ev, handleUpdates); }, + /** * Load data from the passed object, if the object is empty will try to fetch them * autonomously from the storage manager. diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index 2bf23328b..91e1d551d 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -186,7 +186,7 @@ module.exports = Backbone.Model.extend({ * Listen for new rules * @param {Object} collection * @private - */ + * listenRules(collection) { this.stopListening(collection, 'add remove', this.listenRule); this.listenTo(collection, 'add remove', this.listenRule); @@ -199,11 +199,11 @@ module.exports = Backbone.Model.extend({ * Listen for rule changes * @param {Object} model * @private - */ + * listenRule(model) { this.stopListening(model, 'change:style', this.handleUpdates); this.listenTo(model, 'change:style', this.handleUpdates); - }, + },*/ /** * This method handles updates on the editor and tries to store them