Browse Source

Avoid triggering `rte:disable` on component move. Closes #5545

pull/5559/head
Artur Arseniev 2 years ago
parent
commit
ddc3602d90
  1. 2
      src/commands/index.ts
  2. 2
      src/common/index.ts
  3. 14
      src/dom_components/view/ComponentTextView.ts
  4. 4
      src/dom_components/view/ComponentView.ts
  5. 6
      src/rich_text_editor/index.ts

2
src/commands/index.ts

@ -157,7 +157,7 @@ export default class CommandsModule extends Module<CommandsConfig & { pStylePref
const mode = target.get('dmode') || em.get('dmode');
const hideTlb = () => em.stopDefault(defComOptions);
const altMode = includes(modes, mode);
targets.forEach(trg => trg.trigger('disable'));
targets.forEach(trg => trg.trigger('disable', { fromMove: true }));
// Without setTimeout the ghost image disappears
nativeDrag ? setTimeout(hideTlb, 0) : hideTlb();

2
src/common/index.ts

@ -9,6 +9,8 @@ export type SetOptions = Backbone.ModelSetOptions & { avoidStore?: boolean };
export type AddOptions = Backbone.AddOptions & { temporary?: boolean };
export type DisableOptions = { fromMove?: boolean };
export type RemoveOptions = Backbone.Silenceable;
export type EventHandler = Backbone.EventHandler;

14
src/dom_components/view/ComponentTextView.ts

@ -1,5 +1,5 @@
import { bindAll } from 'underscore';
import { ObjectAny } from '../../common';
import { DisableOptions, ObjectAny } from '../../common';
import RichTextEditorModule from '../../rich_text_editor';
import RichTextEditor from '../../rich_text_editor/model/RichTextEditor';
import { off, on } from '../../utils/dom';
@ -99,15 +99,15 @@ export default class ComponentTextView extends ComponentView {
this.toggleEvents(true);
}
onDisable() {
this.disableEditing();
onDisable(opts?: DisableOptions) {
this.disableEditing(opts);
}
/**
* Disable element content editing
* @private
* */
async disableEditing(opts = {}) {
async disableEditing(opts: DisableOptions = {}) {
const { model, rte, activeRte, em } = this;
// There are rare cases when disableEditing is called when the view is already removed
// so, we have to check for the model, this will avoid breaking stuff.
@ -115,7 +115,7 @@ export default class ComponentTextView extends ComponentView {
if (rte) {
try {
await rte.disable(this, activeRte);
await rte.disable(this, activeRte, opts);
} catch (err) {
em.logError(err as any);
}
@ -242,8 +242,8 @@ export default class ComponentTextView extends ComponentView {
// The ownerDocument is from the frame
var elDocs = [this.el.ownerDocument, document];
mixins.off(elDocs, 'mousedown', this.onDisable);
mixins[method](elDocs, 'mousedown', this.onDisable);
mixins.off(elDocs, 'mousedown', this.onDisable as any);
mixins[method](elDocs, 'mousedown', this.onDisable as any);
em[method]('toolbar:run:before', this.onDisable);
if (model) {
model[method]('removed', this.onDisable);

4
src/dom_components/view/ComponentView.ts

@ -1,7 +1,7 @@
import { each, isEmpty, keys, result } from 'underscore';
import { CanvasSpotBuiltInTypes } from '../../canvas/model/CanvasSpot';
import FrameView from '../../canvas/view/FrameView';
import { ExtractMethods, ObjectAny, View } from '../../common';
import { DisableOptions, ExtractMethods, ObjectAny, View } from '../../common';
import { GetSetRuleOptions } from '../../css_composer';
import Editor from '../../editor';
import EditorModel from '../../editor/model/Editor';
@ -140,7 +140,7 @@ Component> {
/**
* Callback executed when the `disable` event is triggered on component
*/
onDisable() {}
onDisable(opts?: DisableOptions) {}
remove() {
super.remove();

6
src/rich_text_editor/index.ts

@ -39,7 +39,7 @@
import { debounce, isFunction, isString } from 'underscore';
import { Module } from '../abstract';
import { Debounced, Model } from '../common';
import { Debounced, DisableOptions, Model } from '../common';
import ComponentView from '../dom_components/view/ComponentView';
import EditorModel from '../editor/model/Editor';
import { createEl, cx, on, removeEl } from '../utils/dom';
@ -398,7 +398,7 @@ export default class RichTextEditorModule extends Module<RichTextEditorConfig &
* @param {Object} rte The instance of already defined RTE
* @private
* */
disable(view: ComponentView, rte?: RichTextEditor) {
disable(view: ComponentView, rte?: RichTextEditor, opts: DisableOptions = {}) {
const { em } = this;
const customRte = this.customRte;
// @ts-ignore
@ -414,7 +414,7 @@ export default class RichTextEditorModule extends Module<RichTextEditorConfig &
if (em) {
em.off(eventsUp, this.updatePosition, this);
em.trigger('rte:disable', view, rte);
!opts.fromMove && em.trigger('rte:disable', view, rte);
}
this.model.unset('currentView');

Loading…
Cancel
Save