From 42a42ebcfb0f4cd3df2c0840c680689dbcdcc02b Mon Sep 17 00:00:00 2001 From: abd-msyukyu-odoo Date: Tue, 5 Apr 2022 14:37:30 +0000 Subject: [PATCH] [IMP] web_editor: flag only editable as unremovable Prior to this change, if a contenteditable=true element was a child of a contenteditable=false element, it was always flagged as unremovable=true. In fact what should happen is that this.editable should be unremovable, but one of its subchildren can be contenteditable=true while having a parent contenteditable=false and not be unremovable. Task-id: 2794990 X-original-commit: 72e2fd7439a0d6e44b5082def35079019371a3b7 Part-of: odoo/odoo#88733 --- .../static/lib/odoo-editor/src/utils/utils.js | 7 +------ .../lib/odoo-editor/test/spec/editor.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/addons/web_editor/static/lib/odoo-editor/src/utils/utils.js b/addons/web_editor/static/lib/odoo-editor/src/utils/utils.js index f954708cef6..a79bb581e07 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/lib/odoo-editor/src/utils/utils.js @@ -962,13 +962,8 @@ export function isUnremovable(node) { if (node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.TEXT_NODE) { return true; } - const isEditableRoot = - node.isContentEditable && - node.parentElement && - !node.parentElement.isContentEditable && - node.nodeName !== 'A'; // links can be their own contenteditable but should be removable by default. return ( - isEditableRoot || + node.oid === 'root' || (node.nodeType === Node.ELEMENT_NODE && (node.getAttribute('t-set') || node.getAttribute('t-call'))) || (node.classList && node.classList.contains('oe_unremovable')) diff --git a/addons/web_editor/static/lib/odoo-editor/test/spec/editor.test.js b/addons/web_editor/static/lib/odoo-editor/test/spec/editor.test.js index 2f0d75a9135..bc314d21d91 100644 --- a/addons/web_editor/static/lib/odoo-editor/test/spec/editor.test.js +++ b/addons/web_editor/static/lib/odoo-editor/test/spec/editor.test.js @@ -2246,6 +2246,24 @@ X[] }); }); + describe('deleterange', () => { + it('should remove element which is contenteditable=true even if their parent is contenteditable=false', async () => { + await testEditor(BasicEditor, { + contentBefore: unformat(` +

before[o

+
+

intruder

+
+

o]after

`), + stepFunction: async editor => { + await deleteBackward(editor); + }, + contentAfter: unformat(` +

before[]after

`), + }); + }); + }); + describe('insertParagraphBreak', () => { describe('Selection collapsed', () => { describe('Basic', () => {