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 d452fff29be..aa5926321dc 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 @@ -3607,13 +3607,18 @@ export class OdooEditor extends EventTarget { // Move selection if next character is zero-width space if (nextCharacter === '\u200B') { focusOffset += 1; - while (focusNode && (!focusNode.textContent[focusOffset] || !closestElement(focusNode).isContentEditable)) { - focusNode = nextLeaf(focusNode); + let newFocusNode = focusNode; + while (newFocusNode && (!newFocusNode.textContent[focusOffset] || !closestElement(newFocusNode).isContentEditable)) { + newFocusNode = nextLeaf(newFocusNode); focusOffset = 0; } - const startContainer = ev.shiftKey ? selection.anchorNode : focusNode; + if (!focusOffset && closestBlock(focusNode) !== closestBlock(newFocusNode)) { + newFocusNode = focusNode; // Do not move selection to next block. + focusOffset = nodeSize(focusNode); + } + const startContainer = ev.shiftKey ? selection.anchorNode : newFocusNode; const startOffset = ev.shiftKey ? selection.anchorOffset : focusOffset; - setSelection(startContainer, startOffset, focusNode, focusOffset); + setSelection(startContainer, startOffset, newFocusNode, focusOffset); } } } 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 8041867dfa7..42259836a9b 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 @@ -5478,6 +5478,24 @@ X[] // Final state: '

ab\u200Bc[]d

' }); }); + it('should move past a zws (collapsed at the end of a block)', async () => { + await testEditor(BasicEditor, { + contentBefore: '

ab[]\u200B

cd

', + stepFunction: async editor => { + triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight'}); + }, + contentAfter: '

ab\u200B[]

cd

', + // Final state: '

ab\u200B

[]cd

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

ab[]\u200B

cd

', + stepFunction: async editor => { + triggerEvent(editor.editable, 'keydown', { key: 'ArrowRight'}); + }, + contentAfter: '

ab\u200B[]

cd

', + // Final state: '

ab\u200B

[]cd

' + }); + }); it('should select a zws', async () => { await testEditor(BasicEditor, { contentBefore: '

[ab]\u200Bcd

',