From a101dfd35eb35db257c9aca2473a29ca89c1bbc0 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Mon, 10 Oct 2022 10:52:07 +0000 Subject: [PATCH] [FIX] web_editor: prevent removal of trailing space on remove last char This fixes a bug that occurred when using BACKSPACE to remove the last character of a text node, if said character was preceded by a space and said text node was succeeded by a
. The space was removed along with the character. This was simply due to a missing state restoration rule to handle this specific case. task-2990229 closes odoo/odoo#102974 X-original-commit: 5e90529388095321da8b504ebf543c4c3054845e Signed-off-by: David Monjoie (dmo) --- .../js/editor/odoo-editor/src/utils/utils.js | 6 ++++ .../odoo-editor/test/spec/editor.test.js | 36 +++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) 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 5d320a827b4..fd357e061b9 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 @@ -2202,6 +2202,12 @@ const priorityRestoreStateRules = [ { direction: DIRECTIONS.LEFT, cType1: CTGROUPS.INLINE, cType2: CTGROUPS.BR }, { spaceVisibility: true }, ], + [ + // Replace a space by   when it was content before and now it is + // a BR (removal of last character before a BR for example). + { direction: DIRECTIONS.RIGHT, cType1: CTGROUPS.CONTENT, cType2: CTGROUPS.BR }, + { spaceVisibility: true }, + ], [ // Replace a space by   when it was visible thanks to a BR which // is now gone. 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 f1d08103229..6a847ddc980 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 @@ -3127,18 +3127,15 @@ X[] await testEditor(BasicEditor, { contentBefore: '

ab []cd

', stepFunction: insertLineBreak, - // The space is converted to a non-breaking - // space so it is visible (because it's before a - //
). - // JW cAfter: '

ab 
[]cd

', - contentAfter: '

ab
[]cd

', // Note: JW seems just wrong here... + // The space is converted to a non-breaking space so it + // is visible (because it's before a
). + contentAfter: '

ab 
[]cd

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

ab[] cd

', stepFunction: insertLineBreak, - // The space is converted to a non-breaking - // space so it is visible (because it's after a - //
). + // The space is converted to a non-breaking space so it + // is visible (because it's after a
). contentAfter: '

ab
[] cd

', }); }); @@ -3235,16 +3232,15 @@ X[] await testEditor(BasicEditor, { contentBefore: '

abc []def

', stepFunction: insertLineBreak, - // JW cAfter: '

abc 
[]def

', - contentAfter: '

abc
[]def

', // Note: JW seems just wrong here + // The space is converted to a non-breaking space so it + // is visible (because it's before a
). + contentAfter: '

abc 
[]def

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

abc[] def

', stepFunction: insertLineBreak, - // The space is converted to a non-breaking - // space so it is visible (because it's before a - //
). - // JW cAfter: '

abc
[] def

', + // The space is converted to a non-breaking space so it + // is visible (because it's before a
). contentAfter: '

abc
[] def

', }); }); @@ -3275,8 +3271,9 @@ X[] await testEditor(BasicEditor, { contentBefore: '

abc []def

', stepFunction: insertLineBreak, - // JW cAfter: '

abc []
def

', - contentAfter: '

abc
[]
def

', // Note: JW seems wrong here + // The space is converted to a non-breaking space so it + // is visible (because it's before a
). + contentAfter: '

abc 
[]
def

', }); }); it('should insert a
at the beginning of a format node', async () => { @@ -3308,10 +3305,9 @@ X[] await testEditor(BasicEditor, { contentBefore: '

ab []cd

', stepFunction: insertLineBreak, - // The space is converted to a non-breaking - // space so it is visible. - // JW cAfter: '

ab 
[]cd

', - contentAfter: '

ab
[]cd

', // Note: JW seems just wrong here... + // The space is converted to a non-breaking space so it + // is visible (because it's before a
). + contentAfter: '

ab 
[]cd

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

ab[] cd

',