diff --git a/src/codeMirror6Scroller.ts b/src/codeMirror6Scroller.ts index b7bb94f..b681f7a 100644 --- a/src/codeMirror6Scroller.ts +++ b/src/codeMirror6Scroller.ts @@ -13,15 +13,15 @@ export default (context: ContentScriptContext): MarkdownEditorContentScriptModul console.log('scrollToLine', lineNumber); // Bounds checking - if (lineNumber < 1) { - lineNumber = 1; + if (lineNumber < 0) { + lineNumber = 0; } - if (lineNumber > editor.state.doc.lines) { - lineNumber = editor.state.doc.lines; + if (lineNumber >= editor.state.doc.lines) { + lineNumber = editor.state.doc.lines - 1; } // Scroll to line, place the line at the *top* of the editor - const lineInfo = editor.state.doc.line(lineNumber); + const lineInfo = editor.state.doc.line(lineNumber + 1); editor.dispatch(editor.state.update({ effects: EditorView.scrollIntoView(lineInfo.from, {y: 'start'}) })); diff --git a/src/webview.js b/src/webview.js index bc4012f..08df6cd 100644 --- a/src/webview.js +++ b/src/webview.js @@ -33,7 +33,7 @@ function copyInnerLink(dataset, text) { function scrollToTop() { webviewApi.postMessage({ name: 'scrollToHeader', - lineno: 1, + lineno: 0, hash: 'rendered-md', }); }