From 7a463ec271efe7d1d456d019645d44bf54586714 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 29 Mar 2023 15:21:31 -0700 Subject: [PATCH] Prefer reusing open tabs when opening md links in editors (#178628) Fixes #81238 --- .../src/util/openDocumentLink.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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),