From 805290a8715955d2b7da156d2e5b7ee13ebe9e0b Mon Sep 17 00:00:00 2001 From: Yiyi Wang Date: Mon, 24 Sep 2018 16:35:19 -0500 Subject: [PATCH] Better scroll sync when user typing in editor (#147) --- package.json | 2 +- src/extension.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 92cb4ff..cb49e4d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/extension.ts b/src/extension.ts index 18e3296..b948ce8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 }, ); }