[FIX] web_editor: undo after columns

Issue:
=====
When you undo a column command, you won't be able to write on that line
anymore.

Steps to reproduce the issue:
=============================
- Go knowledge
- Use column command to add columns
- Do ctrl+z
- Try to write anything

Origin of the issue:
====================
When we apply a columns operations , it will use the current block and
insert it under the first column so the `ouid` of the block will change
to the `oid` of the div (the column) so will will have 2 mutations : one
to remove the block from the root and one to add the block under the
column.
Reverting history will do the operations in reverse order, so it will
remove the block from under the column and the add it under the root but
the `block.ouid` is already set to `oid` of  the column which is
different from the actual `ouid` which is `root` so adding any text to
the block will first add a textnode with `getOuid(node,true) =
block.ouid) != "root"` and `getOuid(node,false) = "root"` so it will
mark `this._toRollBack` as true and the operation is rolled back that's
why we can't add anything anymore.

Soltuion:
=========
Mark the `ouid` of the removed elements as undefined so when we insert
them again we can recalculate it correctly.

task-3693076

closes odoo/odoo#154815

X-original-commit: 16163f135d4fc215361dddf2f4520d08a3b0ac1c
Signed-off-by: Geelen Sébastien (sge) <sge@odoo.com>
Signed-off-by: Mahdi Cheikh Rouhou (macr) <macr@odoo.com>
This commit is contained in:
Mahdi Cheikh Rouhou (macr)
2024-02-21 11:27:59 +00:00
parent 4254e0aba9
commit 1fd3b86de9
2 changed files with 29 additions and 0 deletions
@@ -1534,6 +1534,7 @@ export class OdooEditor extends EventTarget {
const node = this.idFind(mutation.id);
if (node) {
node.remove();
node.ouid = undefined;
}
}
}
@@ -4859,6 +4859,34 @@ X[]
})
});
});
describe('undo', () => {
it('should be able to write after undo', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>[]</p>',
stepFunction: async editor => {
editor.execCommand('columnize', 2);
undo(editor);
await insertText(editor, 'x');
},
contentAfter: '<p>x[]</p>',
});
});
it('should work properly after undo and then redo', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>[]</p>',
stepFunction: async editor => {
editor.execCommand('columnize', 2);
undo(editor);
redo(editor);
await insertText(editor, 'x');
},
contentAfter: columnsContainer(
column(6, '<p>x[]</p>') +
column(6, '<p><br></p>')
) + '<p><br></p>',
});
});
});
});
describe('tables', () => {