Make sure double click in md preview always reveals target line

Fixes #146333
This commit is contained in:
Matt Bierner 2022-03-30 15:49:22 -07:00
parent 8a4f35d96a
commit 590a9bf8a3
No known key found for this signature in database
GPG key ID: 099C331567E11888

View file

@ -339,18 +339,26 @@ class MarkdownPreview extends Disposable implements WebviewResourceProvider {
// fix #82457, find currently opened but unfocused source tab
await vscode.commands.executeCommand('markdown.showSource');
const revealLineInEditor = (editor: vscode.TextEditor) => {
const position = new vscode.Position(line, 0);
const newSelection = new vscode.Selection(position, position);
editor.selection = newSelection;
editor.revealRange(newSelection, vscode.TextEditorRevealType.InCenterIfOutsideViewport);
};
for (const visibleEditor of vscode.window.visibleTextEditors) {
if (this.isPreviewOf(visibleEditor.document.uri)) {
const editor = await vscode.window.showTextDocument(visibleEditor.document, visibleEditor.viewColumn);
const position = new vscode.Position(line, 0);
editor.selection = new vscode.Selection(position, position);
revealLineInEditor(editor);
return;
}
}
await vscode.workspace.openTextDocument(this._resource)
.then(vscode.window.showTextDocument)
.then(undefined, () => {
.then((editor) => {
revealLineInEditor(editor);
}, () => {
vscode.window.showErrorMessage(localize('preview.clickOpenFailed', 'Could not open {0}', this._resource.toString()));
});
}