fallback to setting caret on line node for empty lines

instead of setting at the end of the editor
pull/21833/head
Bruno Windels 2019-05-28 10:34:29 +02:00
parent 4fc23022f4
commit 6b680ff681
1 changed files with 4 additions and 7 deletions

View File

@ -44,16 +44,13 @@ export function setCaretPosition(editor, model, caretPosition) {
let focusNode;
const lineNode = editor.childNodes[lineIndex];
if (lineNode) {
if (lineNode.childNodes.length === 0 && offset === 0) {
focusNode = lineNode;
} else {
focusNode = lineNode.childNodes[nodeIndex];
if (focusNode && focusNode.nodeType === Node.ELEMENT_NODE) {
if (!focusNode) {
focusNode = lineNode;
} else if (focusNode.nodeType === Node.ELEMENT_NODE) {
focusNode = focusNode.childNodes[0];
}
}
}
// node not found, set caret at end
if (!focusNode) {
range.selectNodeContents(editor);