Skip to content

Commit

Permalink
Fix markdown preview restoring to wrong position on restart
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Feb 15, 2019
1 parent 714192f commit 003521e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
18 changes: 11 additions & 7 deletions extensions/markdown-language-features/media/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion extensions/markdown-language-features/media/pre.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

export function onceDocumentLoaded(f: () => void) {
if (document.readyState === 'loading' || document.readyState === 'uninitialized') {
if (document.readyState === 'loading' || document.readyState as string === 'uninitialized') {
document.addEventListener('DOMContentLoaded', f);
} else {
f();
Expand Down
4 changes: 3 additions & 1 deletion extensions/markdown-language-features/preview-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const settings = getSettings();
const vscode = acquireVsCodeApi();

// Set VS Code state
const state = getData('data-state');
let state = getData('data-state');
vscode.setState(state);

const messaging = createPosterForVsCode(vscode);
Expand Down Expand Up @@ -152,6 +152,8 @@ if (settings.scrollEditorWithPreview) {
const line = getEditorLineNumberForPageOffset(window.scrollY);
if (typeof line === 'number' && !isNaN(line)) {
messaging.postMessage('revealLine', { line });
state.line = line;
vscode.setState(state);
}
}
}, 50));
Expand Down
14 changes: 7 additions & 7 deletions extensions/markdown-language-features/preview-src/scroll-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const getCodeLineElements = (() => {
let elements: CodeLineElement[];
return () => {
if (!elements) {
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)));
elements = [{ element: document.body, line: 0 }];
for (const element of document.getElementsByClassName('code-line')) {
const line = +element.getAttribute('data-line')!;
if (!isNaN(line)) {
elements.push({ element: element as HTMLElement, line });
}
}
}
return elements;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jsx": "react",
"sourceMap": true,
"strict": true,
"strictBindCallApply": true,
"noImplicitAny": true,
"noUnusedLocals": true
}
Expand Down

0 comments on commit 003521e

Please sign in to comment.