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 8b3f8cd16cc..cf0f648c5d2 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 @@ -80,6 +80,7 @@ import { prepareUpdate, boundariesOut, getFontSizeDisplayValue, + rightLeafOnlyNotBlockPath, } from './utils/utils.js'; import { editorCommands } from './commands/commands.js'; import { Powerbox } from './powerbox/Powerbox.js'; @@ -2237,7 +2238,11 @@ export class OdooEditor extends EventTarget { fillEmpty(closestBlock(start)); } fillEmpty(closestBlock(range.endContainer)); - const joinWith = range.endContainer; + let joinWith = range.endContainer; + const rightLeaf = rightLeafOnlyNotBlockPath(joinWith).next().value; + if (rightLeaf && rightLeaf.nodeValue === ' ') { + joinWith = rightLeaf; + } // Rejoin blocks that extractContents may have split in two. while ( doJoin && diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 5dfa633b2ff..3f823f0428d 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -2659,7 +2659,8 @@ export function enforceWhitespace(el, offset, direction, rule) { if ( spaceVisibility && !foundVisibleSpaceTextNode && - getState(...rightPos(spaceNode), DIRECTIONS.RIGHT).cType & CTGROUPS.BLOCK + getState(...rightPos(spaceNode), DIRECTIONS.RIGHT).cType & CTGROUPS.BLOCK && + getState(...leftPos(spaceNode), DIRECTIONS.LEFT).cType !== CTYPES.CONTENT ) { spaceVisibility = false; } 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 08b77d11f3d..1631b7a320e 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 @@ -3425,6 +3425,15 @@ X[] contentAfter: `
a []
`, }); }); + it('should transform the space node preceded by a styled element to ', async () => { + await testEditor(BasicEditor, { + contentBefore: `ab [cd]
`, + stepFunction: async editor => { + await insertText(editor, 'x'); + }, + contentAfter: `ab x[]
`, + }); + }); }); describe('insertParagraphBreak', () => {