Skip to content

Commit

Permalink
Fix text component issue on toolbar commands execution. Closes #2294
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 28, 2019
1 parent 35bb143 commit 6f566ec
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/commands/view/SelectComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ export default {
this.toolbar = new Toolbar(toolbar);
var toolbarView = new ToolbarView({
collection: this.toolbar,
editor: this.editor
editor: this.editor,
em
});
toolbarEl.appendChild(toolbarView.render().el);
}
Expand Down
9 changes: 5 additions & 4 deletions src/dom_components/view/ComponentTextView.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export default ComponentView.extend({
}
}

this.rteEnabled = 1;
this.toggleEvents(1);
},

Expand All @@ -67,7 +66,6 @@ export default ComponentView.extend({
this.syncContent();
}

this.rteEnabled = 0;
this.toggleEvents();
},

Expand Down Expand Up @@ -141,14 +139,17 @@ export default ComponentView.extend({
* @param {Boolean} enable
*/
toggleEvents(enable) {
var method = enable ? 'on' : 'off';
const { em } = this;
const mixins = { on, off };
this.em.setEditing(enable);
const method = enable ? 'on' : 'off';
em.setEditing(enable);
this.rteEnabled = !!enable;

// The ownerDocument is from the frame
var elDocs = [this.el.ownerDocument, document];
mixins.off(elDocs, 'mousedown', this.disableEditing);
mixins[method](elDocs, 'mousedown', this.disableEditing);
em[method]('toolbar:run:before', this.disableEditing);

// Avoid closing edit mode on component click
this.$el.off('mousedown', this.disablePropagation);
Expand Down
8 changes: 6 additions & 2 deletions src/dom_components/view/ToolbarButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ export default Backbone.View.extend({
return this.model.get('attributes');
},

initialize(opts) {
this.editor = opts.config.editor;
initialize(opts = {}) {
const { config = {} } = opts;
this.em = config.em;
this.editor = config.editor;
},

handleClick(event) {
event.preventDefault();
event.stopPropagation();
const { em } = this;
em.trigger('toolbar:run:before');
this.execCommand(event);
},

Expand Down
4 changes: 2 additions & 2 deletions src/dom_components/view/ToolbarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import ToolbarButtonView from './ToolbarButtonView';
export default DomainViews.extend({
itemView: ToolbarButtonView,

initialize(opts) {
this.config = { editor: opts.editor || '' };
initialize(opts = {}) {
this.config = { editor: opts.editor || '', em: opts.em };
this.listenTo(this.collection, 'reset', this.render);
}
});

0 comments on commit 6f566ec

Please sign in to comment.