From 1fd3b86de96e88578047bf915f95aa676e618463 Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Mon, 22 Jan 2024 15:42:02 +0100 Subject: [PATCH] [FIX] web_editor: undo after columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Signed-off-by: Mahdi Cheikh Rouhou (macr) --- .../js/editor/odoo-editor/src/OdooEditor.js | 1 + .../odoo-editor/test/spec/editor.test.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index f51e9d3b434..b5da8e40196 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -1534,6 +1534,7 @@ export class OdooEditor extends EventTarget { const node = this.idFind(mutation.id); if (node) { node.remove(); + node.ouid = undefined; } } } diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js index f3f03485976..755b07237c2 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js @@ -4859,6 +4859,34 @@ X[] }) }); }); + describe('undo', () => { + it('should be able to write after undo', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[]

', + stepFunction: async editor => { + editor.execCommand('columnize', 2); + undo(editor); + await insertText(editor, 'x'); + }, + contentAfter: '

x[]

', + }); + }); + it('should work properly after undo and then redo', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[]

', + stepFunction: async editor => { + editor.execCommand('columnize', 2); + undo(editor); + redo(editor); + await insertText(editor, 'x'); + }, + contentAfter: columnsContainer( + column(6, '

x[]

') + + column(6, '


') + ) + '


', + }); + }); + }); }); describe('tables', () => {