Skip to content

Commit

Permalink
Better scroll sync when user typing in editor (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
shd101wyy authored Sep 24, 2018
1 parent f77c3b7 commit 805290a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "markdown-preview-enhanced",
"displayName": "Markdown Preview Enhanced",
"description": "Markdown Preview Enhanced ported to vscode",
"version": "0.3.7",
"version": "0.3.8",
"publisher": "shd101wyy",
"repository": "https://github.com/shd101wyy/vscode-markdown-preview-enhanced",
"bugs": {
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,18 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window.onDidChangeTextEditorSelection((event) => {
if (isMarkdownFile(event.textEditor.document)) {
const previewUri = getPreviewUri(event.textEditor.document.uri);
const firstVisibleScreenRow = getTopVisibleLine(event.textEditor);
const lastVisibleScreenRow = getBottomVisibleLine(event.textEditor);
const topRatio =
(event.selections[0].active.line - firstVisibleScreenRow) /
(lastVisibleScreenRow - firstVisibleScreenRow);
vscode.commands.executeCommand(
"_workbench.htmlPreview.postMessage",
previewUri,
{
command: "changeTextEditorSelection",
line: event.selections[0].active.line,
topRatio
},
);
}
Expand Down

0 comments on commit 805290a

Please sign in to comment.