From 2583c80eed9c78eebd5a2cf6b4d855f99359d3c5 Mon Sep 17 00:00:00 2001 From: Adnan Saiyed Date: Mon, 26 Jun 2023 07:03:21 +0000 Subject: [PATCH] [FIX] web_editor: space before word lost Current behaviour before commit: In website, space before the word is lost when deleting the word. Desired behaviour after commit: Now space is preserved when deleting the word. task-3233352 closes odoo/odoo#148492 X-original-commit: 5f5d12dd1bbdc63a9565aa84f197c4a9bba55d7a Signed-off-by: Antoine Guenet (age) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 7 ++++++- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 3 ++- .../src/js/editor/odoo-editor/test/spec/editor.test.js | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) 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', () => {