diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteForward.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteForward.js index 2dfe628cfdf..eef6eb267e7 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteForward.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/deleteForward.js @@ -54,15 +54,21 @@ export function deleteText(charSize, offset, direction, alreadyMoved) { restore(); // If the removed element was not visible content, propagate the deletion. + const parentState = getState(parentElement, firstSplitOffset, direction); if ( isZWS || (isSpace && - getState(parentElement, firstSplitOffset, direction).cType !== CTYPES.CONTENT) + (parentState.cType !== CTYPES.CONTENT || parentState.node === undefined)) ) { - if(direction === DIRECTIONS.LEFT) { + if (direction === DIRECTIONS.LEFT) { parentElement.oDeleteBackward(firstSplitOffset, alreadyMoved); } else { - parentElement.oDeleteForward(firstSplitOffset, alreadyMoved); + if (isSpace && parentState.node == undefined) { + // multiple invisible space at the start of the node + this.oDeleteForward(offset, alreadyMoved); + } else { + parentElement.oDeleteForward(firstSplitOffset, alreadyMoved); + } } if (isZWS) { fillEmpty(parentElement); 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 e30b54016fc..3f26718ddb7 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 @@ -433,6 +433,31 @@ X[] contentAfter: `

[] def

`, }); }); + it('should remove invisible empty space at the start', async () => { + await testEditor(BasicEditor, { + contentBefore: `

[] def

`, + stepFunction: async editor => { + await deleteForward(editor); + }, + contentAfter: `

[]ef

`, + }); + }); + it('should remove invisible empty space at the start (2)', async () => { + await testEditor(BasicEditor, { + // The first 3 spaces are invisible : considered + // formating by the browser. + // The   is visible (space 1). + // The last 3 spaces are consider as 1 visble space and + // two formating spaces (space 2). + contentBefore: `

[]   def

`, + stepFunction: async editor => { + await deleteForward(editor); + }, + // Space 1 is deleted and space 2 should be transformed + // to a   to stay visible. + contentAfter: `

[] def

`, + }); + }); }); describe('white spaces', () => { describe('no intefering spaces', () => {