Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Fix mystery text deletion #1155

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/component/handlers/edit/editOnInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ function editOnInput(editor: DraftEditor): void {
}
}

if (
anchorNode.nodeType === Node.TEXT_NODE &&
(anchorNode.previousSibling !== null || anchorNode.nextSibling !== null)
) {
// When typing at the beginning of a visual line, Chrome splits the text
// nodes into two. Why? No one knows. This commit is suspicious:
// https://chromium.googlesource.com/chromium/src/+/a3b600981286b135632371477f902214c55a1724
// To work around, we'll merge the sibling text nodes back into this one.
const span = anchorNode.parentNode;
anchorNode.nodeValue = span.textContent;
for (
let child = span.firstChild;
child !== null;
child = child.nextSibling
) {
if (child !== anchorNode) {
span.removeChild(child);
}
}
}

var domText = anchorNode.textContent;
var editorState = editor._latestEditorState;
var offsetKey = nullthrows(findAncestorOffsetKey(anchorNode));
Expand Down