From 63f8ce3a584a09a303863d4e2f486525370b6836 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:42:13 +0100 Subject: [PATCH] fix: editor getPositionAtLine when line index exceeds line count --- src/utils/editor.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils/editor.ts b/src/utils/editor.ts index 3788ba6..607f63c 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -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))