Skip to content

Commit

Permalink
Start of move to terminal view command
Browse files Browse the repository at this point in the history
Part of #126248
  • Loading branch information
Tyriar committed Jun 16, 2021
1 parent 0e9445a commit c551cf8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export interface ITerminalService {
moveGroup(source: ITerminalInstance, target: ITerminalInstance): void;
moveInstance(source: ITerminalInstance, target: ITerminalInstance, side: 'before' | 'after'): void;
moveToEditor(source: ITerminalInstance): void;
moveToTerminalView(source?: ITerminalInstance): Promise<void>;

/**
* Perform an action with the active terminal instance, if the terminal does
Expand Down Expand Up @@ -246,6 +247,7 @@ export interface ITerminalEditorService {
readonly terminalEditorInstances: ITerminalInstance[];

createEditor(instance: ITerminalInstance): Promise<void>;
detachActiveEditorInstance(): ITerminalInstance;
}

export interface IRemoteTerminalService extends IOffProcessTerminalService {
Expand Down
14 changes: 14 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ export function registerTerminalActions() {
}
});

registerAction2(class extends Action2 {
constructor() {
super({
id: TerminalCommandId.MoveToTerminalView,
title: { value: localize('workbench.action.terminal.moveToTerminalView', "Move From Editor to Terminal View"), original: 'Move From Editor to Terminal View' },
f1: true,
category
});
}
async run(accessor: ServicesAccessor) {
await accessor.get(ITerminalService).moveToTerminalView();
}
});

registerAction2(class extends Action2 {
constructor() {
super({
Expand Down
12 changes: 12 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalEditorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ export class TerminalEditorService implements ITerminalEditorService {
});
this.terminalEditorInstances.push(instance);
}

detachActiveEditorInstance(): ITerminalInstance {
const activeEditor = this._editorService.activeEditor;
if (!(activeEditor instanceof TerminalEditorInput)) {
throw new Error('Active editor is not a terminal');
}
const instance = activeEditor.terminalInstance;
this._editorInputs.delete(instance.instanceId);
// TODO: Ensure the terminal process doesn't get disposed here
activeEditor.dispose();
return instance;
}
}
35 changes: 35 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ export class TerminalService implements ITerminalService {
}

moveToEditor(source: ITerminalInstance): void {
if (source.target === TerminalTarget.Editor) {
return;
}
const sourceGroup = this.getGroupForInstance(source);
if (!sourceGroup) {
return;
Expand All @@ -772,6 +775,38 @@ export class TerminalService implements ITerminalService {
this._terminalEditorService.createEditor(source);
}

async moveToTerminalView(source?: ITerminalInstance): Promise<void> {
if (!source) {
source = this._terminalEditorService.detachActiveEditorInstance();
if (!source) {
return;
}
}

if (source.target !== TerminalTarget.Editor) {
return;
}
source.target = TerminalTarget.TerminalView;

// TODO: Share code with joinInstances
const group = this._instantiationService.createInstance(TerminalGroup, this._terminalContainer, undefined);
group.onPanelOrientationChanged((orientation) => this._onPanelOrientationChanged.fire(orientation));
this._terminalGroups.push(group);
group.addDisposable(group.onDisposed(this._onGroupDisposed.fire, this._onGroupDisposed));
group.addDisposable(group.onInstancesChanged(this._onInstancesChanged.fire, this._onInstancesChanged));

group.addInstance(source);
this.setActiveInstance(source);
await this.showPanel(true);
// TODO: Shouldn't this happen automatically?
source.setVisible(true);

// Fire events
this._onInstancesChanged.fire();
this._onGroupsChanged.fire();
this._onActiveGroupChanged.fire();
}

protected _initInstanceListeners(instance: ITerminalInstance): void {
instance.addDisposable(instance.onDisposed(this._onInstanceDisposed.fire, this._onInstanceDisposed));
instance.addDisposable(instance.onTitleChanged(this._onInstanceTitleChanged.fire, this._onInstanceTitleChanged));
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ export const enum TerminalCommandId {
SearchWorkspace = 'workbench.action.terminal.searchWorkspace',
AttachToRemoteTerminal = 'workbench.action.terminal.attachToSession',
DetachProcess = 'workbench.action.terminal.detachProcess',
MoveToEditor = 'workbench.action.terminal.moveToEditor'
MoveToEditor = 'workbench.action.terminal.moveToEditor',
MoveToTerminalView = 'workbench.action.terminal.moveToTerminalView',
}

export const DEFAULT_COMMANDS_TO_SKIP_SHELL: string[] = [
Expand Down

0 comments on commit c551cf8

Please sign in to comment.