[FIX] web_editor: only remove zws when necessary

Before this commit
The zws character (`\u200B`) was removed regardless if it was added by
the editor.

After this commit
The zws character (`\u200B`) is removed only when it is added by the
editor using `oe-zws-empty-inline`.

Part-of: odoo/odoo#99812
This commit is contained in:
Nicolas Bayet
2022-09-20 13:48:38 +02:00
parent 7eaac5f08c
commit 3645e25f36
2 changed files with 36 additions and 17 deletions
@@ -134,6 +134,7 @@ class Sanitize {
if (
node.nodeType === Node.TEXT_NODE &&
node.textContent.includes('\u200B') &&
node.parentElement.hasAttribute('oe-zws-empty-inline') &&
(
node.textContent.length > 1 ||
// There can be multiple ajacent text nodes, in which case
@@ -3043,23 +3043,41 @@ X[]
});
});
describe('insertLineBreak', () => {
describe('Selection not collapsed', () => {
it('should insert a char into an empty span', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>ab<span>[]\u200B</span>cd</p>',
stepFunction: async editor => {
await insertText(editor, 'x');
},
contentAfter: '<p>ab<span>x[]</span>cd</p>',
});
await testEditor(BasicEditor, {
contentBefore: '<p>uv <span>[]\u200B</span> wx</p>',
stepFunction: async editor => {
await insertText(editor, 'y');
},
contentAfter: '<p>uv <span>y[]</span> wx</p>',
});
describe('ZWS', () => {
it('should insert a char into an empty span without removing the zws', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>ab<span>[]\u200B</span>cd</p>',
stepFunction: async editor => {
await insertText(editor, 'x');
},
contentAfter: '<p>ab<span>x[]\u200B</span>cd</p>',
});
});
it('should insert a char into an empty span surrounded by space without removing the zws', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>ab <span>[]\u200B</span> cd</p>',
stepFunction: async editor => {
await insertText(editor, 'x');
},
contentAfter: '<p>ab <span>x[]\u200B</span> cd</p>',
});
});
it('should insert a char into a oe-zws-empty-inline span removing the zws and oe-zws-empty-inline', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>ab<span oe-zws-empty-inline="">[]\u200B</span>cd</p>',
stepFunction: async editor => {
await insertText(editor, 'x');
},
contentAfter: '<p>ab<span>x[]</span>cd</p>',
});
});
it('should insert a char into a oe-zws-empty-inline span surrounded by space without removing the zws and oe-zws-empty-inline', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>ab<span oe-zws-empty-inline="">[]\u200B</span>cd</p>',
stepFunction: async editor => {
await insertText(editor, 'x');
},
contentAfter: '<p>ab<span>x[]</span>cd</p>',
});
});
});