Skip to content

Commit

Permalink
fix: editor getPositionAtLine when line index exceeds line count
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Jan 6, 2025
1 parent 7dd98cb commit 63f8ce3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 63f8ce3

Please sign in to comment.