From 2a6de3533e449ac5a44245a7587e8b4a422af22a Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:16:57 +0800 Subject: [PATCH] fix: getLineAtCursor bug with zero-position marks fix: #605 --- src/utils/editor.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/utils/editor.ts b/src/utils/editor.ts index c8d4124..2e357fe 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -163,15 +163,14 @@ function getRangeAtCursor(editor: Zotero.EditorInstance) { function getLineAtCursor(editor: Zotero.EditorInstance) { const position = getPositionAtCursor(editor); + const lastPos = getEditorCore(editor).view.state.tr.doc.content.size; let i = 0; - let lastPos = 0; let currentPos = getPositionAtLine(editor, 0); - while (currentPos !== lastPos) { + while (currentPos <= lastPos) { if (position <= currentPos) { break; } i += 1; - lastPos = currentPos; currentPos = getPositionAtLine(editor, i); } return i;