[FIX] web_editor: properly convert backticks in split text nodes

Wrong syntax made it so that having a text node after the text node in
which we're inserting a closing backtick character, converted all the
text after the backtick to the word "NaN". This fixes that syntax error
and ensures such cases are properly handled.

X-original-commit: 2833b42c09582dbcfed334d9fe6628a8eaf476b8
Part-of: odoo/odoo#110784
This commit is contained in:
Antoine Guenet
2023-01-24 10:20:44 +01:00
parent 05b8b0a7d6
commit f261efa1d7
2 changed files with 42 additions and 3 deletions
@@ -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);
@@ -5727,6 +5727,46 @@ X[]
contentAfter: '<p>a<code class="o_inline_code">b`cd`[]e</code>f</p>',
});
});
it('should convert text into inline code even when text nodes are split', async () => {
// BEFORE
await testEditor(BasicEditor, {
contentBefore: '<p>b`c[]d</p>',
stepFunction: async editor => {
editor.document.getSelection().anchorNode.before(document.createTextNode('a'));
insertText(editor, '`');
},
contentAfter: '<p>ab<code class="o_inline_code">c</code>\u200B[]d</p>',
});
// AFTER
await testEditor(BasicEditor, {
contentBefore: '<p>a`b[]c</p>',
stepFunction: async editor => {
editor.document.getSelection().anchorNode.after(document.createTextNode('d'));
insertText(editor, '`');
},
contentAfter: '<p>a<code class="o_inline_code">b</code>\u200B[]cd</p>',
});
// BOTH
await testEditor(BasicEditor, {
contentBefore: '<p>b`c[]d</p>',
stepFunction: async editor => {
editor.document.getSelection().anchorNode.before(document.createTextNode('a'));
editor.document.getSelection().anchorNode.after(document.createTextNode('e'));
insertText(editor, '`');
},
contentAfter: '<p>ab<code class="o_inline_code">c</code>\u200B[]de</p>',
});
});
it('should convert text into inline code even when the other backtick is in a separate text node', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>ab[]c</p>',
stepFunction: async editor => {
editor.document.getSelection().anchorNode.before(document.createTextNode('`'));
insertText(editor, '`');
},
contentAfter: '<p>\u200B<code class="o_inline_code">ab</code>\u200B[]c</p>',
});
});
});
});