diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js index 1439d579283..092e3f32676 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js @@ -291,7 +291,11 @@ export const editorCommands = { currentNode = lastChildNode || currentNode; selection.removeAllRanges(); const newRange = new Range(); - const lastPosition = rightPos(currentNode); + let lastPosition = rightPos(currentNode); + if (lastPosition[0] === editor.editable) { + // Correct the position if it happens to be in the editable root. + lastPosition = getDeepestPosition(...lastPosition); + } newRange.setStart(lastPosition[0], lastPosition[1]); newRange.setEnd(lastPosition[0], lastPosition[1]); selection.addRange(newRange); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js index 569e4ac4512..f701d4eda83 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js @@ -1182,7 +1182,7 @@ describe('Copy and paste', () => { stepFunction: async editor => { await pasteHtml(editor, ''); }, - contentAfter: '

12

[]

34

', + contentAfter: '

12

[]34

', }); }); it('should paste the text of an li into another li', async () => { @@ -1496,7 +1496,7 @@ describe('Copy and paste', () => { stepFunction: async editor => { await pasteOdooEditorHtml(editor, '
b
'); }, - contentAfter: '

a

b
[]

b

', + contentAfter: '

a

b

[]b

', }); }); it('should not paste unsafe content', async () => {