Browse Source

Fix conflicts in RTE with multiple editor instances #3475

pull/3563/head
Artur Arseniev 5 years ago
parent
commit
ff6f87a16a
  1. 4
      src/dom_components/view/ComponentTextView.js
  2. 12
      src/rich_text_editor/index.js
  3. 16
      src/rich_text_editor/model/RichTextEditor.js

4
src/dom_components/view/ComponentTextView.js

@ -28,7 +28,7 @@ export default ComponentView.extend({
* Enable element content editing
* @private
* */
onActive(e) {
async onActive(e) {
const { rte, em } = this;
// We place this before stopPropagation in case of nested
@ -45,7 +45,7 @@ export default ComponentView.extend({
if (rte) {
try {
this.activeRte = rte.enable(this, this.activeRte);
this.activeRte = await rte.enable(this, this.activeRte);
} catch (err) {
em.logError(err);
}

12
src/rich_text_editor/index.js

@ -289,25 +289,27 @@ export default () => {
* @param {Object} rte The instance of already defined RTE
* @private
* */
enable(view, rte) {
async enable(view, rte) {
lastEl = view.el;
const { customRte } = this;
const canvas = config.em.get('Canvas');
const em = config.em;
const el = view.getChildrenContainer();
const customRte = this.customRte;
lastElPos = canvas.getElementPos(lastEl);
toolbar.style.display = '';
rte = customRte ? customRte.enable(el, rte) : this.initRte(el).enable();
const rteInst = await (customRte
? customRte.enable(el, rte)
: this.initRte(el).enable());
if (em) {
setTimeout(this.updatePosition.bind(this), 0);
em.off(eventsUp, this.updatePosition, this);
em.on(eventsUp, this.updatePosition, this);
em.trigger('rte:enable', view, rte);
em.trigger('rte:enable', view, rteInst);
}
return rte;
return rteInst;
},
/**

16
src/rich_text_editor/model/RichTextEditor.js

@ -80,18 +80,18 @@ export default class RichTextEditor {
this.setEl(el);
this.updateActiveActions = this.updateActiveActions.bind(this);
const settAct = settings.actions || [];
settAct.forEach((action, i) => {
const acts = (settings.actions || []).map(action => {
let result = action;
if (typeof action === 'string') {
action = defActions[action];
result = { ...defActions[action] };
} else if (defActions[action.name]) {
action = { ...defActions[action.name], ...action };
result = { ...defActions[action.name], ...action };
}
settAct[i] = action;
return result;
});
const actions = settAct.length
? settAct
: Object.keys(defActions).map(action => defActions[action]);
const actions = acts.length
? acts
: Object.keys(defActions).map(a => defActions[a]);
settings.classes = {
...{

Loading…
Cancel
Save