[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
This commit is contained in:
abd-msyukyu-odoo
2022-04-14 10:50:07 +02:00
committed by Tom De Caluwé
parent 0c5c2a37a5
commit 42a42ebcfb
2 changed files with 19 additions and 6 deletions
@@ -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'))
@@ -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(`
<p>before[o</p>
<div contenteditable="false">
<div contenteditable="true"><p>intruder</p></div>
</div>
<p>o]after</p>`),
stepFunction: async editor => {
await deleteBackward(editor);
},
contentAfter: unformat(`
<p>before[]after</p>`),
});
});
});
describe('insertParagraphBreak', () => {
describe('Selection collapsed', () => {
describe('Basic', () => {