diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index c65b80f0b2c..c5ac7726d8a 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -398,8 +398,8 @@ export interface ICreateContributedTerminalProfileOptions { } export enum TerminalLocation { - Panel = 0, - Editor = 1 + Panel = 1, + Editor = 2 } export const enum TerminalLocationString { diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 1fec9f34151..022b7f61886 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -926,8 +926,8 @@ declare module 'vscode' { } export enum TerminalLocation { - Panel = 0, - Editor = 1, + Panel = 1, + Editor = 2, } export interface TerminalEditorLocationOptions { diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 5ebcf7368d6..a3eec5aac11 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -174,7 +174,7 @@ export class ExtHostTerminal { return this._id; } - private _serializeParentTerminal(location?: TerminalLocation | vscode.TerminalEditorLocationOptions | vscode.TerminalSplitLocationOptions | { splitActiveTerminal: boolean }, parentTerminal?: ExtHostTerminalIdentifier, internalLocation?: TerminalLocation | { viewColumn: number, preserveState?: boolean } | { splitActiveTerminal: boolean }): TerminalLocation | vscode.TerminalEditorLocationOptions | { parentTerminal: ExtHostTerminalIdentifier } | { splitActiveTerminal: boolean, location?: TerminalLocation } | vscode.TerminalEditorLocationOptions | undefined { + private _serializeParentTerminal(location?: TerminalLocation | vscode.TerminalEditorLocationOptions | vscode.TerminalSplitLocationOptions | { splitActiveTerminal: boolean }, parentTerminal?: ExtHostTerminalIdentifier, internalLocation?: TerminalLocation | { viewColumn: number, preserveState?: boolean } | { splitActiveTerminal: boolean }): TerminalLocation | vscode.TerminalEditorLocationOptions | { parentTerminal: ExtHostTerminalIdentifier } | { splitActiveTerminal: boolean } | vscode.TerminalEditorLocationOptions | undefined { if (typeof location === 'object' && 'parentTerminal' in location) { return parentTerminal ? { parentTerminal } : undefined; } else if (internalLocation) { diff --git a/src/vs/workbench/contrib/terminal/browser/terminal.ts b/src/vs/workbench/contrib/terminal/browser/terminal.ts index 07436d4c0e8..cb0621bb428 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminal.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminal.ts @@ -188,6 +188,7 @@ export interface ITerminalService extends ITerminalInstanceHost { getFindHost(instance?: ITerminalInstance): ITerminalFindHost; getDefaultProfileName(): string; + resolveLocation(location?: ITerminalLocationOptions): TerminalLocation | undefined } /** diff --git a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts index 2901cc6a637..9018b13fed4 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts @@ -1661,7 +1661,7 @@ export function registerTerminalActions() { if (terminalService.isProcessSupportRegistered) { eventOrOptions = !eventOrOptions || eventOrOptions instanceof MouseEvent ? {} : eventOrOptions; - eventOrOptions.location = eventOrOptions.location || terminalService.defaultLocation; + let instance: ITerminalInstance | undefined; if (folders.length <= 1) { // Allow terminal service to handle the path when there is only a @@ -2004,8 +2004,12 @@ export function validateTerminalName(name: string): { content: string, severity: } function convertOptionsOrProfileToOptions(optionsOrProfile?: ICreateTerminalOptions | ITerminalProfile): ICreateTerminalOptions | undefined { - if (typeof optionsOrProfile === 'object' && 'profileName' in optionsOrProfile) { - return { config: optionsOrProfile as ITerminalProfile }; + if (typeof optionsOrProfile === 'object') { + if ('profileName' in optionsOrProfile) { + return { config: optionsOrProfile as ITerminalProfile, location: (optionsOrProfile as ICreateTerminalOptions).location }; + } else if ('location' in optionsOrProfile) { + return { location: (optionsOrProfile as ICreateTerminalOptions).location }; + } } return optionsOrProfile; } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalMenus.ts b/src/vs/workbench/contrib/terminal/browser/terminalMenus.ts index 1266ccb3b01..7a421ad0b1a 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalMenus.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalMenus.ts @@ -611,7 +611,7 @@ export function getTerminalActionBarArgs(location: ITerminalLocationOptions, pro for (const contributed of contributedProfiles) { const isDefault = contributed.title === defaultProfileName; const title = isDefault ? localize('defaultTerminalProfile', "{0} (Default)", contributed.title.replace(/[\n\r\t]/g, '')) : contributed.title.replace(/[\n\r\t]/g, ''); - dropdownActions.push(new Action(TerminalCommandId.NewWithProfile, title, undefined, true, () => terminalService.createTerminal({ + dropdownActions.push(new Action('contributed', title, undefined, true, () => terminalService.createTerminal({ config: { extensionIdentifier: contributed.extensionIdentifier, id: contributed.id, @@ -620,7 +620,7 @@ export function getTerminalActionBarArgs(location: ITerminalLocationOptions, pro location }))); const splitLocation = location === TerminalLocation.Editor ? { viewColumn: SIDE_GROUP } : { splitActiveTerminal: true }; - submenuActions.push(new Action(TerminalCommandId.NewWithProfile, title, undefined, true, () => terminalService.createTerminal({ + submenuActions.push(new Action('contributed-split', title, undefined, true, () => terminalService.createTerminal({ config: { extensionIdentifier: contributed.extensionIdentifier, id: contributed.id, @@ -656,10 +656,11 @@ export function getTerminalActionBarArgs(location: ITerminalLocationOptions, pro submenuActions.unshift(defaultSubmenuProfileAction); } + const primaryActionLocation = terminalService.resolveLocation(location); const primaryAction = instantiationService.createInstance( MenuItemAction, { - id: location === TerminalLocation.Panel ? TerminalCommandId.New : TerminalCommandId.CreateTerminalEditor, + id: primaryActionLocation === TerminalLocation.Editor ? TerminalCommandId.CreateTerminalEditor : TerminalCommandId.New, title: localize('terminal.new', "New Terminal"), icon: Codicon.plus }, @@ -670,9 +671,9 @@ export function getTerminalActionBarArgs(location: ITerminalLocationOptions, pro }, { shouldForwardArgs: true, - arg: { location } as ICreateTerminalOptions, + arg: { location: primaryActionLocation } as ICreateTerminalOptions, }); const dropdownAction = new Action('refresh profiles', 'Launch Profile...', 'codicon-chevron-down', true); - return { primaryAction, dropdownAction, dropdownMenuActions: dropdownActions, className: 'terminal-tab-actions' }; + return { primaryAction, dropdownAction, dropdownMenuActions: dropdownActions, className: `terminal-tab-actions-${terminalService.resolveLocation(location)}` }; } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalService.ts b/src/vs/workbench/contrib/terminal/browser/terminalService.ts index b2fbb0e30e8..d0c783cd313 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalService.ts @@ -1156,7 +1156,7 @@ export class TerminalService implements ITerminalService { // Launch the contributed profile if (contributedProfile) { - const resolvedLocation = this._resolveLocation(options?.location); + const resolvedLocation = this.resolveLocation(options?.location); const splitActiveTerminal = typeof options?.location === 'object' && 'splitActiveTerminal' in options.location ? options.location.splitActiveTerminal : false; const location = splitActiveTerminal ? resolvedLocation === TerminalLocation.Editor ? { viewColumn: SIDE_GROUP } : { splitActiveTerminal: true } : resolvedLocation; await this._createContributedTerminalProfile(contributedProfile.extensionIdentifier, contributedProfile.id, { @@ -1187,9 +1187,8 @@ export class TerminalService implements ITerminalService { } this._evaluateLocalCwd(shellLaunchConfig); - const location = this._resolveLocation(options?.location) || this.defaultLocation; + const location = this.resolveLocation(options?.location) || this.defaultLocation; const parent = this._getSplitParent(options?.location); - if (parent) { return this._splitTerminal(shellLaunchConfig, location, parent); } else { @@ -1235,16 +1234,16 @@ export class TerminalService implements ITerminalService { return instance; } - private _resolveLocation(location?: ITerminalLocationOptions): TerminalLocation | undefined { - if (!location) { - return location; - } else if (typeof location === 'object') { + resolveLocation(location?: ITerminalLocationOptions): TerminalLocation | undefined { + if (location && typeof location === 'object') { if ('parentTerminal' in location) { - return location.parentTerminal.target; + // since we don't set the target unless it's an editor terminal, this is necessary + return !location.parentTerminal.target ? TerminalLocation.Panel : location.parentTerminal.target; } else if ('viewColumn' in location) { return TerminalLocation.Editor; } else if ('splitActiveTerminal' in location) { - return this._activeInstance?.target || this.defaultLocation; + // since we don't set the target unless it's an editor terminal, this is necessary + return !this._activeInstance?.target ? TerminalLocation.Panel : this._activeInstance?.target; } } return location;