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 }, ); }