From dcf0070ca658baf2d1cdea97f43c697b269e6d9b Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Tue, 5 Sep 2017 13:59:38 +0200 Subject: [PATCH] Prevent undo/redo while focused on inputs --- src/canvas/index.js | 9 +++++++++ src/editor/model/Editor.js | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/canvas/index.js b/src/canvas/index.js index 7cd64d7e8..a2fe55429 100644 --- a/src/canvas/index.js +++ b/src/canvas/index.js @@ -337,6 +337,15 @@ module.exports = () => { }; }, + /** + * Detects if some input is focused (input elements, text components, etc.) + * Used internally, for example, to avoid undo/redo in text editing mode + * @return {Boolean} + */ + isInputFocused() { + return this.getFrameEl().contentDocument.activeElement.tagName !== 'BODY'; + }, + /** * Start autoscroll */ diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index 939a66307..5ec0ff8ef 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -209,9 +209,12 @@ module.exports = Backbone.Model.extend({ * @private * */ initUndoManager() { + const canvas = this.get('Canvas'); + if (this.um) { return; } + var cmp = this.get('DomComponents'); if(cmp && this.config.undoManager) { var that = this; @@ -223,11 +226,18 @@ module.exports = Backbone.Model.extend({ this.set('UndoManager', this.um); key('⌘+z, ctrl+z', () => { + if (canvas.isInputFocused()) { + return; + } + that.um.undo(true); that.trigger('component:update'); }); key('⌘+shift+z, ctrl+shift+z', () => { + if (canvas.isInputFocused()) { + return; + } that.um.redo(true); that.trigger('component:update'); }); @@ -262,6 +272,7 @@ module.exports = Backbone.Model.extend({ that.trigger('change:selectedComponent'); } }; + UndoManager.removeUndoType("change"); UndoManager.addUndoType("change:style", customUndoType); UndoManager.addUndoType("change:content", customUndoType);