Skip to content

Commit

Permalink
Scroll to the first line when the preview hits top
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Oct 31, 2021
1 parent 886235f commit 69b8bbf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ActiveLineMarker } from './activeLineMarker'
import { onceDocumentLoaded } from './events'
import { createPosterForVsCode } from './messaging'
import { getEditorLineNumberForPageOffset, scrollToRevealSourceLine } from './scroll-sync'
import { getSettings, getData } from './settings'
import { getData, getSettings } from './settings'
import throttle = require('lodash.throttle');

declare let acquireVsCodeApi: any
Expand Down Expand Up @@ -89,7 +89,6 @@ window.addEventListener('message', (event) => {
return
}

//console.log("GOT MESSAGE", event.data);
switch (event.data.type) {
case 'onDidChangeTextEditorSelection':
marker.onDidChangeTextEditorSelection(event.data.line)
Expand Down Expand Up @@ -161,7 +160,10 @@ if (settings.scrollEditorWithPreview) {
scrollDisabled = false
} else {
const line = getEditorLineNumberForPageOffset(window.scrollY)
if (typeof line === 'number' && !isNaN(line)) {
if (window.scrollY === 0) {
// scroll to top, document title does not have a data-line attribute
messaging.postMessage('revealLine', { line: 1 })
} else if (typeof line === 'number' && !isNaN(line)) {
messaging.postMessage('revealLine', { line })
}
}
Expand Down

0 comments on commit 69b8bbf

Please sign in to comment.