Reveal line 0 in editor when markdown preview scrolls to top

Fixes #61815
This commit is contained in:
Matt Bierner 2018-10-25 10:54:39 -07:00
parent 295ff96f26
commit fe63c7e2f2
2 changed files with 6 additions and 7 deletions

File diff suppressed because one or more lines are too long

View file

@ -24,13 +24,13 @@ const getCodeLineElements = (() => {
let elements: CodeLineElement[];
return () => {
if (!elements) {
elements = Array.prototype.map.call(
elements = ([{ element: document.body, line: 0 }]).concat(Array.prototype.map.call(
document.getElementsByClassName('code-line'),
(element: any) => {
const line = +element.getAttribute('data-line');
return { element, line };
})
.filter((x: any) => !isNaN(x.line));
.filter((x: any) => !isNaN(x.line)));
}
return elements;
};
@ -49,8 +49,7 @@ export function getElementsForSourceLine(targetLine: number): { previous: CodeLi
for (const entry of lines) {
if (entry.line === lineNumber) {
return { previous: entry, next: undefined };
}
else if (entry.line > lineNumber) {
} else if (entry.line > lineNumber) {
return { previous, next: entry };
}
previous = entry;