diff --git a/src/commands/browseRepoAtRevision.ts b/src/commands/browseRepoAtRevision.ts index a37a281..f91814c 100644 --- a/src/commands/browseRepoAtRevision.ts +++ b/src/commands/browseRepoAtRevision.ts @@ -7,7 +7,15 @@ import { toGitLensFSUri } from '../git/fsProvider'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { Messages } from '../messages'; -import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri, openWorkspace } from './common'; +import { + ActiveEditorCommand, + command, + CommandContext, + Commands, + getCommandUri, + openWorkspace, + OpenWorkspaceLocation, +} from './common'; export interface BrowseRepoAtRevisionCommandArgs { uri?: Uri; @@ -63,8 +71,9 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand { uri = toGitLensFSUri(sha, gitUri.repoPath!); gitUri = GitUri.fromRevisionUri(uri); - openWorkspace(uri, `${paths.basename(gitUri.repoPath!)} @ ${gitUri.shortSha}`, { - openInNewWindow: args.openInNewWindow, + openWorkspace(uri, { + location: args.openInNewWindow ? OpenWorkspaceLocation.NewWindow : OpenWorkspaceLocation.AddToWorkspace, + name: `${paths.basename(gitUri.repoPath!)} @ ${gitUri.shortSha}`, }); if (!args.openInNewWindow) { diff --git a/src/commands/common.ts b/src/commands/common.ts index 0464042..010652b 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -732,16 +732,22 @@ export async function openEditor( } } -export function openWorkspace(uri: Uri, name: string, options: { openInNewWindow?: boolean } = {}) { - if (options.openInNewWindow) { - void commands.executeCommand(BuiltInCommands.OpenFolder, uri, true); +export enum OpenWorkspaceLocation { + CurrentWindow = 'currentWindow', + NewWindow = 'newWindow', + AddToWorkspace = 'addToWorkspace', +} - return true; +export function openWorkspace( + uri: Uri, + options: { location?: OpenWorkspaceLocation; name?: string } = { location: OpenWorkspaceLocation.CurrentWindow }, +): void { + if (options?.location === OpenWorkspaceLocation.AddToWorkspace) { + const count = workspace.workspaceFolders?.length ?? 0; + return void workspace.updateWorkspaceFolders(count, 0, { uri: uri, name: options?.name }); } - return workspace.updateWorkspaceFolders( - workspace.workspaceFolders != null ? workspace.workspaceFolders.length : 0, - null, - { uri: uri, name: name }, - ); + return void commands.executeCommand(BuiltInCommands.OpenFolder, uri, { + forceNewWindow: options?.location === OpenWorkspaceLocation.NewWindow, + }); }