[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) <age@odoo.com>
This commit is contained in:
Adnan Saiyed
2024-01-10 06:12:21 +00:00
parent 3e37dc21d5
commit 2583c80eed
3 changed files with 17 additions and 2 deletions
@@ -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 &&
@@ -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;
}
@@ -3425,6 +3425,15 @@ X[]
contentAfter: `<p>a&nbsp;[]</p>`,
});
});
it('should transform the space node preceded by a styled element to &nbsp;', async () => {
await testEditor(BasicEditor, {
contentBefore: `<p><strong>ab</strong> [cd]</p>`,
stepFunction: async editor => {
await insertText(editor, 'x');
},
contentAfter: `<p><strong>ab</strong>&nbsp;x[]</p>`,
});
});
});
describe('insertParagraphBreak', () => {