Skip to content

Commit

Permalink
fix: scroll 1-line shift
Browse files Browse the repository at this point in the history
  • Loading branch information
alondmnt committed Apr 20, 2024
1 parent 6be4b05 commit ee2cb23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/codeMirror6Scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
}));
Expand Down
2 changes: 1 addition & 1 deletion src/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function copyInnerLink(dataset, text) {
function scrollToTop() {
webviewApi.postMessage({
name: 'scrollToHeader',
lineno: 1,
lineno: 0,
hash: 'rendered-md',
});
}
Expand Down

0 comments on commit ee2cb23

Please sign in to comment.