[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 <br>. 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) <dmo@odoo.com>
This commit is contained in:
Antoine Guenet
2022-10-11 12:13:39 +02:00
parent b731ae7bb1
commit a101dfd35e
2 changed files with 22 additions and 20 deletions
@@ -2202,6 +2202,12 @@ const priorityRestoreStateRules = [
{ direction: DIRECTIONS.LEFT, cType1: CTGROUPS.INLINE, cType2: CTGROUPS.BR },
{ spaceVisibility: true },
],
[
// Replace a space by &nbsp; 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 &nbsp; when it was visible thanks to a BR which
// is now gone.
@@ -3127,18 +3127,15 @@ X[]
await testEditor(BasicEditor, {
contentBefore: '<p>ab []cd</p>',
stepFunction: insertLineBreak,
// The space is converted to a non-breaking
// space so it is visible (because it's before a
// <br>).
// JW cAfter: '<p>ab&nbsp;<br>[]cd</p>',
contentAfter: '<p>ab <br>[]cd</p>', // Note: JW seems just wrong here...
// The space is converted to a non-breaking space so it
// is visible (because it's before a <br>).
contentAfter: '<p>ab&nbsp;<br>[]cd</p>',
});
await testEditor(BasicEditor, {
contentBefore: '<p>ab[] cd</p>',
stepFunction: insertLineBreak,
// The space is converted to a non-breaking
// space so it is visible (because it's after a
// <br>).
// The space is converted to a non-breaking space so it
// is visible (because it's after a <br>).
contentAfter: '<p>ab<br>[]&nbsp;cd</p>',
});
});
@@ -3235,16 +3232,15 @@ X[]
await testEditor(BasicEditor, {
contentBefore: '<p>abc <b>[]def</b></p>',
stepFunction: insertLineBreak,
// JW cAfter: '<p>abc&nbsp;<br><b>[]def</b></p>',
contentAfter: '<p>abc <b><br>[]def</b></p>', // Note: JW seems just wrong here
// The space is converted to a non-breaking space so it
// is visible (because it's before a <br>).
contentAfter: '<p>abc&nbsp;<b><br>[]def</b></p>',
});
await testEditor(BasicEditor, {
contentBefore: '<p>abc<b>[] def </b></p>',
stepFunction: insertLineBreak,
// The space is converted to a non-breaking
// space so it is visible (because it's before a
// <br>).
// JW cAfter: '<p>abc<br><b>[]&nbsp;def</b></p>',
// The space is converted to a non-breaking space so it
// is visible (because it's before a <br>).
contentAfter: '<p>abc<b><br>[]&nbsp;def </b></p>',
});
});
@@ -3275,8 +3271,9 @@ X[]
await testEditor(BasicEditor, {
contentBefore: '<p><b>abc []</b>def</p>',
stepFunction: insertLineBreak,
// JW cAfter: '<p><b>abc&nbsp;[]<br></b>def</p>',
contentAfter: '<p><b>abc <br>[]</b>def</p>', // Note: JW seems wrong here
// The space is converted to a non-breaking space so it
// is visible (because it's before a <br>).
contentAfter: '<p><b>abc&nbsp;<br>[]</b>def</p>',
});
});
it('should insert a <br> at the beginning of a format node', async () => {
@@ -3308,10 +3305,9 @@ X[]
await testEditor(BasicEditor, {
contentBefore: '<p><b>ab []cd</b></p>',
stepFunction: insertLineBreak,
// The space is converted to a non-breaking
// space so it is visible.
// JW cAfter: '<p><b>ab&nbsp;<br>[]cd</b></p>',
contentAfter: '<p><b>ab <br>[]cd</b></p>', // Note: JW seems just wrong here...
// The space is converted to a non-breaking space so it
// is visible (because it's before a <br>).
contentAfter: '<p><b>ab&nbsp;<br>[]cd</b></p>',
});
await testEditor(BasicEditor, {
contentBefore: '<p><b>ab[] cd</b></p>',