Browse Source

Prevent undo/redo while focused on inputs

pull/281/head
Artur Arseniev 9 years ago
parent
commit
dcf0070ca6
  1. 9
      src/canvas/index.js
  2. 11
      src/editor/model/Editor.js

9
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
*/

11
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);

Loading…
Cancel
Save