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 8055344966c..5b5270399bd 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 @@ -3200,9 +3200,8 @@ export class OdooEditor extends EventTarget { } sibling = textNode.nextSibling; while (sibling && sibling.nodeType === Node.TEXT_NODE) { - sibling.textContent =+ textNode.textContent; - textNode.remove(); - textNode = sibling; + textNode.textContent += sibling.textContent; + sibling.remove(); sibling = textNode.nextSibling; } setSelection(textNode, offset); 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 37fa81d9b61..dc0c171485b 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 @@ -5727,6 +5727,46 @@ X[] contentAfter: '

ab`cd`[]ef

', }); }); + it('should convert text into inline code even when text nodes are split', async () => { + // BEFORE + await testEditor(BasicEditor, { + contentBefore: '

b`c[]d

', + stepFunction: async editor => { + editor.document.getSelection().anchorNode.before(document.createTextNode('a')); + insertText(editor, '`'); + }, + contentAfter: '

abc\u200B[]d

', + }); + // AFTER + await testEditor(BasicEditor, { + contentBefore: '

a`b[]c

', + stepFunction: async editor => { + editor.document.getSelection().anchorNode.after(document.createTextNode('d')); + insertText(editor, '`'); + }, + contentAfter: '

ab\u200B[]cd

', + }); + // BOTH + await testEditor(BasicEditor, { + contentBefore: '

b`c[]d

', + stepFunction: async editor => { + editor.document.getSelection().anchorNode.before(document.createTextNode('a')); + editor.document.getSelection().anchorNode.after(document.createTextNode('e')); + insertText(editor, '`'); + }, + contentAfter: '

abc\u200B[]de

', + }); + }); + it('should convert text into inline code even when the other backtick is in a separate text node', async () => { + await testEditor(BasicEditor, { + contentBefore: '

ab[]c

', + stepFunction: async editor => { + editor.document.getSelection().anchorNode.before(document.createTextNode('`')); + insertText(editor, '`'); + }, + contentAfter: '

\u200Bab\u200B[]c

', + }); + }); }); });