diff --git a/extensions/markdown-language-features/src/util/openDocumentLink.ts b/extensions/markdown-language-features/src/util/openDocumentLink.ts index f29661571a5..4fc423d3675 100644 --- a/extensions/markdown-language-features/src/util/openDocumentLink.ts +++ b/extensions/markdown-language-features/src/util/openDocumentLink.ts @@ -37,6 +37,18 @@ export class MdLinkOpener { return vscode.commands.executeCommand('revealInExplorer', uri); case 'file': { + // If no explicit viewColumn is given, check if the editor is already open in a tab + if (typeof viewColumn === 'undefined') { + for (const tab of vscode.window.tabGroups.all.flatMap(x => x.tabs)) { + if (tab.input instanceof vscode.TabInputText) { + if (tab.input.uri.fsPath === uri.fsPath) { + viewColumn = tab.group.viewColumn; + break; + } + } + } + } + return vscode.commands.executeCommand('vscode.open', uri, { selection: resolved.position ? new vscode.Range(resolved.position.line, resolved.position.character, resolved.position.line, resolved.position.character) : undefined, viewColumn: viewColumn ?? getViewColumn(fromResource),