🐛 遇到 br 时全选

This commit is contained in:
Vanessa 2022-08-01 11:30:43 +08:00
parent 0da5bb7e71
commit b1dcfe6845

View file

@ -52,21 +52,22 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
firstChild = firstChild.firstChild;
}
}
let lastChild = editElement.lastChild;
let lastChild = editElement.lastChild as HTMLElement;
while (lastChild) {
if (lastChild.nodeType === 3) {
if (lastChild.textContent !== "") {
range.setEnd(lastChild, lastChild.textContent.length);
break;
}
lastChild = lastChild.previousSibling;
lastChild = lastChild.previousSibling as HTMLElement;
} else {
if ((lastChild as HTMLElement).classList.contains("render-node") ||
(lastChild as HTMLElement).classList.contains("img")) {
if (lastChild.classList.contains("render-node") ||
lastChild.classList.contains("img") ||
lastChild.tagName === "BR") {
range.setEndAfter(lastChild);
break;
}
lastChild = lastChild.lastChild;
lastChild = lastChild.lastChild as HTMLElement;
}
}
protyle.toolbar.render(protyle, range);