Browse Source

Use insertLineBreak for the default RTE

pull/4134/head
Artur Arseniev 5 years ago
parent
commit
75cd582a8d
  1. 42
      src/rich_text_editor/model/RichTextEditor.js

42
src/rich_text_editor/model/RichTextEditor.js

@ -77,6 +77,7 @@ export default class RichTextEditor {
el[RTE_KEY] = this; el[RTE_KEY] = this;
this.setEl(el); this.setEl(el);
this.updateActiveActions = this.updateActiveActions.bind(this); this.updateActiveActions = this.updateActiveActions.bind(this);
this.__onKeydown = this.__onKeydown.bind(this);
const acts = (settings.actions || []).map(action => { const acts = (settings.actions || []).map(action => {
let result = action; let result = action;
@ -173,26 +174,37 @@ export default class RichTextEditor {
} }
enable() { enable() {
if (this.enabled) { if (this.enabled) return this;
return this; return this.__toggleEffects(true);
}
disable() {
return this.__toggleEffects(false);
}
__toggleEffects(enable = false) {
const method = enable ? on : off;
const { el, doc } = this;
this.actionbarEl().style.display = enable ? '' : 'none';
el.contentEditable = !!enable;
method(el, 'mouseup keyup', this.updateActiveActions);
method(doc, 'keydown', this.__onKeydown);
this.enabled = enable;
if (enable) {
this.syncActions();
this.updateActiveActions();
el.focus();
} }
this.actionbarEl().style.display = '';
this.el.contentEditable = true;
on(this.el, 'mouseup keyup', this.updateActiveActions);
this.syncActions();
this.updateActiveActions();
this.el.focus();
this.enabled = 1;
return this; return this;
} }
disable() { __onKeydown(event) {
this.actionbarEl().style.display = 'none'; if (event.key === 'Enter') {
this.el.contentEditable = false; this.doc.execCommand('insertLineBreak');
off(this.el, 'mouseup keyup', this.updateActiveActions); event.preventDefault();
this.enabled = 0; }
return this;
} }
/** /**

Loading…
Cancel
Save