[FIX] web_editor: split text node on insert after delete range
The `insert` command was splitting the selection's starting text node only if the selection was collapsed. But after deleting the range, the selection is inevitably collapsed and therefore the same should be done. closes odoo/odoo#138549 X-original-commit: 06a375db7e6250b388d410010a3d1c50e8af1326 Signed-off-by: Antoine Guenet (age) <age@odoo.com> Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -150,18 +150,17 @@ export const editorCommands = {
|
||||
insert: (editor, content) => {
|
||||
if (!content) return;
|
||||
const selection = editor.document.getSelection();
|
||||
const range = selection.getRangeAt(0);
|
||||
let startNode;
|
||||
let insertBefore = false;
|
||||
if (selection.isCollapsed) {
|
||||
if (range.startContainer.nodeType === Node.TEXT_NODE) {
|
||||
insertBefore = !range.startOffset;
|
||||
splitTextNode(range.startContainer, range.startOffset, DIRECTIONS.LEFT);
|
||||
startNode = range.startContainer;
|
||||
}
|
||||
} else {
|
||||
if (!selection.isCollapsed) {
|
||||
editor.deleteRange(selection);
|
||||
}
|
||||
const range = selection.getRangeAt(0);
|
||||
if (range.startContainer.nodeType === Node.TEXT_NODE) {
|
||||
insertBefore = !range.startOffset;
|
||||
splitTextNode(range.startContainer, range.startOffset, DIRECTIONS.LEFT);
|
||||
startNode = range.startContainer;
|
||||
}
|
||||
|
||||
const container = document.createElement('fake-element');
|
||||
const containerFirstChild = document.createElement('fake-element-fc');
|
||||
|
||||
Reference in New Issue
Block a user