[FIX] web_editor: allow to delete/replace text after toggle to grid mode

When toggling a snippet to grid mode, if it has None columns (e.g. Text)
or if it has contents located outside of the row element (e.g. Picture),
the contents are wrapped inside a column and then put inside the row.
However, after this operation, it is impossible to delete or replace the
text in this newly created column.

As mentioned in commit [1], this happens because there is an unwanted
rollback in the history, which should be prevented by resetting the
nodes unbreakable id (i.e. the `ouid` property).

This commit makes this property reset and therefore allows to delete or
replace the text after the toggle to grid mode.

[1]: https://github.com/odoo/odoo/commit/e33b802b05b41df20e13ebc44bc5b78edae50bb8

task-3324775

X-original-commit: 5bd354802a9aae9575806ad83350e0b002efa2fa
Part-of: odoo/odoo#124513
This commit is contained in:
Soukéina Bojabza
2023-06-12 11:22:02 +02:00
parent d1da2928e9
commit 0f84b3aed7
@@ -2,6 +2,7 @@
'use strict';
import {qweb} from 'web.core';
import {descendants} from "@web_editor/js/editor/odoo-editor/src/utils/utils";
const rowSize = 50; // 50px.
// Maximum number of rows that can be added when dragging a grid item.
export const additionalRowLimit = 10;
@@ -84,6 +85,13 @@ export function _gridCleanUp(rowEl, columnEl) {
*/
export function _toggleGridMode(containerEl) {
let rowEl = containerEl.querySelector(':scope > .row');
// Avoid an unwanted rollback that prevents from deleting the text.
const avoidRollback = (el) => {
for (const node of descendants(el)) {
node.ouid = undefined;
}
};
// For the snippets having elements outside of the row (and therefore not in
// a column), create a column and put these elements in it so they can also
// be placed in the grid.
@@ -94,6 +102,7 @@ export function _toggleGridMode(containerEl) {
for (let i = outOfRowEls.length - 1; i >= 0; i--) {
columnEl.prepend(outOfRowEls[i]);
}
avoidRollback(columnEl);
rowEl.prepend(columnEl);
}
@@ -111,6 +120,7 @@ export function _toggleGridMode(containerEl) {
for (let i = containerChildren.length - 1; i >= 0; i--) {
columnEl.prepend(containerChildren[i]);
}
avoidRollback(columnEl);
rowEl.appendChild(columnEl);
containerEl.appendChild(rowEl);
}