diff --git a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts index b254ee0e3934e..a23b9c92a3f56 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts @@ -114,7 +114,7 @@ export function registerTerminalActions() { async run(accessor: ServicesAccessor) { const terminalService = accessor.get(ITerminalService); if (terminalService.isProcessSupportRegistered) { - const instance = terminalService.createTerminal(); + const instance = terminalService.createTerminal({ target: terminalService.configHelper.config.defaultLocation }); if (!instance) { return; } @@ -425,7 +425,7 @@ export function registerTerminalActions() { } async run(accessor: ServicesAccessor) { const terminalService = accessor.get(ITerminalService); - const instance = terminalService.getActiveOrCreateInstance(); + const instance = terminalService.activeInstance || terminalService.createTerminal({ target: TerminalLocation.TerminalView }); if (!instance) { return; } @@ -1611,16 +1611,25 @@ export function registerTerminalActions() { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.US_BACKTICK, mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.US_BACKTICK }, weight: KeybindingWeight.WorkbenchContrib + }, + description: { + description: 'workbench.action.terminal.new', + args: [{ + name: 'eventOrOptions', + schema: { + type: 'object' + } + }] } }); } - async run(accessor: ServicesAccessor, event: unknown) { + async run(accessor: ServicesAccessor, eventOrOptions: MouseEvent | ICreateTerminalOptions | undefined) { const terminalService = accessor.get(ITerminalService); const terminalGroupService = accessor.get(ITerminalGroupService); const workspaceContextService = accessor.get(IWorkspaceContextService); const commandService = accessor.get(ICommandService); const folders = workspaceContextService.getWorkspace().folders; - if (event instanceof MouseEvent && (event.altKey || event.ctrlKey)) { + if (eventOrOptions && eventOrOptions instanceof MouseEvent && (eventOrOptions.altKey || eventOrOptions.ctrlKey)) { const activeInstance = terminalService.activeInstance; if (activeInstance) { const cwd = await getCwdForSplit(terminalService.configHelper, activeInstance); @@ -1630,11 +1639,13 @@ export function registerTerminalActions() { } if (terminalService.isProcessSupportRegistered) { + eventOrOptions = !eventOrOptions || eventOrOptions instanceof MouseEvent ? {} : eventOrOptions; + eventOrOptions.target = eventOrOptions.target || terminalService.configHelper.config.defaultLocation; let instance: ITerminalInstance | undefined; if (folders.length <= 1) { // Allow terminal service to handle the path when there is only a // single root - instance = terminalService.createTerminal(); + instance = terminalService.createTerminal(eventOrOptions); } else { const options: IPickOptions = { placeHolder: localize('workbench.action.terminal.newWorkspacePlaceholder', "Select current working directory for new terminal") @@ -1644,11 +1655,8 @@ export function registerTerminalActions() { // Don't create the instance if the workspace picker was canceled return; } - instance = terminalService.createTerminal( - { - cwd: workspace.uri - } - ); + eventOrOptions.cwd = workspace.uri; + instance = terminalService.createTerminal(eventOrOptions); } terminalService.setActiveInstance(instance); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalService.ts b/src/vs/workbench/contrib/terminal/browser/terminalService.ts index 85a54deb03b95..9cd0524c45335 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalService.ts @@ -1022,6 +1022,7 @@ export class TerminalService implements ITerminalService { } createTerminal(options?: ICreateTerminalOptions): ITerminalInstance { + console.log(options); const shellLaunchConfig = this._convertProfileToShellLaunchConfig(options?.config || options); if (options?.cwd) { @@ -1044,7 +1045,7 @@ export class TerminalService implements ITerminalService { this._evaluateLocalCwd(shellLaunchConfig); let instance: ITerminalInstance; - if (options?.target === TerminalLocation.Editor || this.configHelper.config.defaultLocation === TerminalLocation.Editor) { + if (options?.target === TerminalLocation.Editor) { instance = this.createInstance(shellLaunchConfig); instance.target = TerminalLocation.Editor; this._terminalEditorService.openEditor(instance); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalView.ts b/src/vs/workbench/contrib/terminal/browser/terminalView.ts index 0d9c3777d419e..624f0c99e1c9f 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalView.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalView.ts @@ -136,7 +136,7 @@ export class TerminalViewPane extends ViewPane { if (this._terminalService.isProcessSupportRegistered) { if (this._terminalsInitialized) { if (!hadTerminals) { - this._terminalService.createTerminal(); + this._terminalService.createTerminal({ target: TerminalLocation.TerminalView }); } } else { this._terminalsInitialized = true;