[FIX] web_editor: prevent recording the o_draggable class changes

Since commit [1], which removed jQueryUI for the drag and drop, the
history when editing breaks easily.

Steps to reproduce:
- Drag and drop "Text-Image", save and go back to edit mode.
- Click on a column, move it to the right using the arrow and then to
  the left, still with the arrow.
- Undo: no issue, the column went to the right.
- Undo: nothing changed => the column should have gone to the left.
- Undo: the column goes to the left => there should not be a third undo
  since we only did two changes. 
- Redo: no issue, the column goes to right.
- Redo: nothing changed => the column should have gone to the left.
- Nothing to redo anymore => the column never goes to the left again.

This happens because with the new drag and drop, an `o_draggable` class
is added on the elements when their editor are started, which adds
mutations in the history. Even though it does not explicitely add a
step, these mutations are well reverted when undoing/redoing (e.g. this
is what happens when nothing changes in the steps to reproduce).

This commit fixes this history issue by ignoring the mutations linked to
the `o_draggable` class.

Note that commit [2] already fixed other `o_draggable` class issues.
This commit therefore fixes them in a more general way.

[1]: https://github.com/odoo/odoo/commit/7594d71ca8610d5947e80f325ccb57abc23c2c76
[2]: https://github.com/odoo/odoo/commit/32a6729dd094d53eb4a653ebb9d69d2b8cbe2390

task-3698536

closes odoo/odoo#150687

Signed-off-by: Guillaume Dieleman (gdi) <gdi@odoo.com>
This commit is contained in:
Soukéina Bojabza
2024-02-06 14:29:02 +00:00
parent 4f29bebb02
commit a015f17ce6
2 changed files with 1 additions and 3 deletions
@@ -120,10 +120,8 @@ var SnippetEditor = Widget.extend({
// _initDragAndDrop function. So adding it here is probably
// useless. To check. The fact that that class is added in any
// case should probably reviewed in master anyway (TODO).
this.options.wysiwyg.odooEditor.observerUnactive('image_drag_and_drop');
this.$target[0].classList.add("o_draggable");
this.draggableComponentImgs = this._initDragAndDrop("img", ".o_draggable", this.$target[0]);
this.options.wysiwyg.odooEditor.observerActive('image_drag_and_drop');
}
} else {
this.$('.o_overlay_move_options').addClass('d-none');
@@ -486,7 +486,7 @@ export class Wysiwyg extends Component {
plugins: options.editorPlugins,
direction: options.direction || localization.direction || 'ltr',
collaborationClientAvatarUrl: this._getCollaborationClientAvatarUrl(),
renderingClasses: ['o_dirty', 'o_transform_removal', 'oe_edited_link', 'o_menu_loading'],
renderingClasses: ["o_dirty", "o_transform_removal", "oe_edited_link", "o_menu_loading", "o_draggable"],
dropImageAsAttachment: options.dropImageAsAttachment,
foldSnippets: !!options.foldSnippets,
useResponsiveFontSizes: options.useResponsiveFontSizes,