fix: editor getPositionAtLine when line index exceeds line count

This commit is contained in:
windingwind 2025-01-06 19:42:13 +01:00
parent 7dd98cbd87
commit 63f8ce3a58

View File

@ -247,6 +247,13 @@ function getPositionAtLine(
type: "start" | "end" = "end",
): number {
const core = getEditorCore(editor);
const lineCount = getLineCount(editor);
if (lineIndex < 0) {
return 0;
}
if (lineIndex >= lineCount) {
return core.view.state.doc.content.size;
}
const lineNodeDesc =
core.view.docView.children[
Math.max(0, Math.min(core.view.docView.children.length - 1, lineIndex))