diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js index 1c128a2e264..6bd02e7d485 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js @@ -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 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 c0e56630bfa..cd6d3de6117 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 @@ -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: '
ab[]\u200Bcd
', - stepFunction: async editor => { - await insertText(editor, 'x'); - }, - contentAfter: 'abx[]cd
', - }); - await testEditor(BasicEditor, { - contentBefore: 'uv []\u200B wx
', - stepFunction: async editor => { - await insertText(editor, 'y'); - }, - contentAfter: 'uv y[] wx
', - }); + describe('ZWS', () => { + it('should insert a char into an empty span without removing the zws', async () => { + await testEditor(BasicEditor, { + contentBefore: 'ab[]\u200Bcd
', + stepFunction: async editor => { + await insertText(editor, 'x'); + }, + contentAfter: 'abx[]\u200Bcd
', + }); + }); + it('should insert a char into an empty span surrounded by space without removing the zws', async () => { + await testEditor(BasicEditor, { + contentBefore: 'ab []\u200B cd
', + stepFunction: async editor => { + await insertText(editor, 'x'); + }, + contentAfter: 'ab x[]\u200B cd
', + }); + }); + 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: 'ab[]\u200Bcd
', + stepFunction: async editor => { + await insertText(editor, 'x'); + }, + contentAfter: 'abx[]cd
', + }); + }); + 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: 'ab[]\u200Bcd
', + stepFunction: async editor => { + await insertText(editor, 'x'); + }, + contentAfter: 'abx[]cd
', }); }); });