mirror of
https://github.com/Microsoft/vscode
synced 2024-10-02 17:32:41 +00:00
be sure that terminal target gets set for the instance (#138875)
This commit is contained in:
parent
60ac527e79
commit
578eb0d4ae
|
@ -179,12 +179,14 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
|
|||
private _labelComputer?: TerminalLabelComputer;
|
||||
private _userHome?: string;
|
||||
private _hasScrollBar?: boolean;
|
||||
private _target?: TerminalLocation | undefined;
|
||||
|
||||
get target(): TerminalLocation | undefined { return this.xterm?.target; }
|
||||
get target(): TerminalLocation | undefined { return this._target; }
|
||||
set target(value: TerminalLocation | undefined) {
|
||||
if (this.xterm) {
|
||||
this.xterm.target = value;
|
||||
}
|
||||
this._target = value;
|
||||
}
|
||||
|
||||
get instanceId(): number { return this._instanceId; }
|
||||
|
@ -559,7 +561,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
|
|||
throw new Error('Terminal disposed of during xterm.js creation');
|
||||
}
|
||||
|
||||
const xterm = this._instantiationService.createInstance(XtermTerminal, Terminal, this._configHelper, this._cols, this._rows);
|
||||
const xterm = this._instantiationService.createInstance(XtermTerminal, Terminal, this._configHelper, this._cols, this._rows, this.target || TerminalLocation.Panel);
|
||||
this.xterm = xterm;
|
||||
const lineDataEventAddon = new LineDataEventAddon();
|
||||
this.xterm.raw.loadAddon(lineDataEventAddon);
|
||||
|
@ -701,7 +703,6 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
|
|||
throw new Error('xterm elements not set after open');
|
||||
}
|
||||
|
||||
|
||||
this._setAriaLabel(xterm.raw, this._instanceId, this._title);
|
||||
|
||||
xterm.raw.attachCustomKeyEventHandler((event: KeyboardEvent): boolean => {
|
||||
|
|
|
@ -13,13 +13,7 @@ import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/term
|
|||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
|
||||
import { TerminalLocation, TerminalSettingId } from 'vs/platform/terminal/common/terminal';
|
||||
import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
|
||||
import { editorBackground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { ansiColorIdentifiers, TERMINAL_BACKGROUND_COLOR, TERMINAL_CURSOR_BACKGROUND_COLOR, TERMINAL_CURSOR_FOREGROUND_COLOR, TERMINAL_FOREGROUND_COLOR, TERMINAL_SELECTION_BACKGROUND_COLOR } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
|
||||
import { ICommandTracker, ITerminalFont, TERMINAL_VIEW_ID } from 'vs/workbench/contrib/terminal/common/terminal';
|
||||
import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
import { isSafari } from 'vs/base/browser/browser';
|
||||
import { IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
@ -28,6 +22,12 @@ import { TerminalStorageKeys } from 'vs/workbench/contrib/terminal/common/termin
|
|||
import { INotificationService, IPromptChoice, Severity } from 'vs/platform/notification/common/notification';
|
||||
import { CommandTrackerAddon } from 'vs/workbench/contrib/terminal/browser/xterm/commandTrackerAddon';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
|
||||
import { editorBackground } from 'vs/platform/theme/common/colorRegistry';
|
||||
import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
|
||||
import { TERMINAL_FOREGROUND_COLOR, TERMINAL_BACKGROUND_COLOR, TERMINAL_CURSOR_FOREGROUND_COLOR, TERMINAL_CURSOR_BACKGROUND_COLOR, TERMINAL_SELECTION_BACKGROUND_COLOR, ansiColorIdentifiers } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
|
||||
import { Color } from 'vs/base/common/color';
|
||||
|
||||
// How long in milliseconds should an average frame take to render for a notification to appear
|
||||
// which suggests the fallback DOM-based renderer
|
||||
|
@ -45,7 +45,6 @@ let WebglAddon: typeof WebglAddonType;
|
|||
export class XtermTerminal extends DisposableStore implements IXtermTerminal {
|
||||
/** The raw xterm.js instance */
|
||||
readonly raw: RawXtermTerminal;
|
||||
target?: TerminalLocation;
|
||||
|
||||
private _core: IXtermCore;
|
||||
private static _suggestedRendererType: 'canvas' | 'dom' | undefined = undefined;
|
||||
|
@ -63,6 +62,12 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal {
|
|||
|
||||
get commandTracker(): ICommandTracker { return this._commandTrackerAddon; }
|
||||
|
||||
private _target: TerminalLocation | undefined;
|
||||
set target(location: TerminalLocation | undefined) {
|
||||
this._target = location;
|
||||
}
|
||||
get target(): TerminalLocation | undefined { return this._target; }
|
||||
|
||||
/**
|
||||
* @param xtermCtor The xterm.js constructor, this is passed in so it can be fetched lazily
|
||||
* outside of this class such that {@link raw} is not nullable.
|
||||
|
@ -72,6 +77,7 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal {
|
|||
private readonly _configHelper: TerminalConfigHelper,
|
||||
cols: number,
|
||||
rows: number,
|
||||
location: TerminalLocation,
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
||||
@ILogService private readonly _logService: ILogService,
|
||||
@INotificationService private readonly _notificationService: INotificationService,
|
||||
|
@ -80,7 +86,7 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal {
|
|||
@IViewDescriptorService private readonly _viewDescriptorService: IViewDescriptorService
|
||||
) {
|
||||
super();
|
||||
|
||||
this.target = location;
|
||||
const font = this._configHelper.getFont(undefined, true);
|
||||
const config = this._configHelper.config;
|
||||
const editorOptions = this._configurationService.getValue<IEditorOptions>('editor');
|
||||
|
@ -125,6 +131,7 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal {
|
|||
this._updateUnicodeVersion();
|
||||
}
|
||||
}));
|
||||
|
||||
this.add(this._themeService.onDidColorThemeChange(theme => this._updateTheme(theme)));
|
||||
this.add(this._viewDescriptorService.onDidChangeLocation(({ views }) => {
|
||||
if (views.some(v => v.id === TERMINAL_VIEW_ID)) {
|
||||
|
@ -133,7 +140,6 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal {
|
|||
}));
|
||||
|
||||
// Load addons
|
||||
|
||||
this._updateUnicodeVersion();
|
||||
|
||||
this._commandTrackerAddon = new CommandTrackerAddon();
|
||||
|
@ -148,7 +154,6 @@ export class XtermTerminal extends DisposableStore implements IXtermTerminal {
|
|||
attachToElement(container: HTMLElement) {
|
||||
// Update the theme when attaching as the terminal location could have changed
|
||||
this._updateTheme();
|
||||
|
||||
if (!this._container) {
|
||||
this.raw.open(container);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import { QuickAccess } from './quickaccess';
|
|||
export enum Selector {
|
||||
TerminalView = `#terminal`,
|
||||
Xterm = `#terminal .terminal-wrapper`,
|
||||
XtermEditor = `.editor-instance .terminal-wrapper`,
|
||||
TabsEntry = '.terminal-tabs-entry',
|
||||
XtermFocused = '.terminal.xterm.focus',
|
||||
PlusButton = '.codicon-plus',
|
||||
|
@ -27,6 +28,7 @@ export enum TerminalCommandIdWithValue {
|
|||
NewWithProfile = 'workbench.action.terminal.newWithProfile',
|
||||
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell',
|
||||
AttachToSession = 'workbench.action.terminal.attachToSession',
|
||||
CreateNew = 'workbench.action.terminal.new'
|
||||
}
|
||||
|
||||
export enum TerminalCommandId {
|
||||
|
@ -35,7 +37,6 @@ export enum TerminalCommandId {
|
|||
Unsplit = 'workbench.action.terminal.unsplit',
|
||||
Join = 'workbench.action.terminal.join',
|
||||
Show = 'workbench.action.terminal.toggleTerminal',
|
||||
CreateNew = 'workbench.action.terminal.new',
|
||||
CreateNewEditor = 'workbench.action.createTerminalEditor',
|
||||
SplitEditor = 'workbench.action.createTerminalEditorSide',
|
||||
MoveToPanel = 'workbench.action.terminal.moveToTerminalPanel',
|
||||
|
@ -57,8 +58,8 @@ export class Terminal {
|
|||
|
||||
async runCommand(commandId: TerminalCommandId): Promise<void> {
|
||||
await this.quickaccess.runCommand(commandId, commandId === TerminalCommandId.Join);
|
||||
if (commandId === TerminalCommandId.Show || commandId === TerminalCommandId.CreateNew) {
|
||||
return await this._waitForTerminal();
|
||||
if (commandId === TerminalCommandId.Show) {
|
||||
return await this._waitForTerminal(undefined);
|
||||
}
|
||||
await this.code.dispatchKeybinding('enter');
|
||||
await this.quickinput.waitForQuickInputClosed();
|
||||
|
@ -78,6 +79,9 @@ export class Terminal {
|
|||
// Reset
|
||||
await this.code.dispatchKeybinding('Backspace');
|
||||
}
|
||||
if (commandId === TerminalCommandIdWithValue.CreateNew) {
|
||||
return await this._waitForTerminal(value);
|
||||
}
|
||||
await this.code.dispatchKeybinding(altKey ? 'Alt+Enter' : 'enter');
|
||||
await this.quickinput.waitForQuickInputClosed();
|
||||
}
|
||||
|
@ -194,8 +198,8 @@ export class Terminal {
|
|||
return (this.code.driver as any).page;
|
||||
}
|
||||
|
||||
private async _waitForTerminal(): Promise<void> {
|
||||
private async _waitForTerminal(value: any): Promise<void> {
|
||||
await this.code.waitForElement(Selector.XtermFocused);
|
||||
await this.code.waitForTerminalBuffer(Selector.Xterm, lines => lines.some(line => line.length > 0));
|
||||
await this.code.waitForTerminalBuffer(value === 'editor' ? Selector.XtermEditor : Selector.Xterm, lines => lines.some(line => line.length > 0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue }
|
|||
export function setup() {
|
||||
describe('Terminal Editors', () => {
|
||||
let terminal: Terminal;
|
||||
|
||||
let app: Application;
|
||||
// Acquire automation API
|
||||
before(async function () {
|
||||
const app = this.app as Application;
|
||||
app = this.app as Application;
|
||||
terminal = app.workbench.terminal;
|
||||
});
|
||||
|
||||
|
@ -65,5 +65,14 @@ export function setup() {
|
|||
await terminal.clickPlusButton();
|
||||
await terminal.assertEditorGroupCount(1);
|
||||
});
|
||||
|
||||
it('should create a terminal in the editor area by default', async () => {
|
||||
await app.workbench.settingsEditor.addUserSetting('terminal.integrated.defaultLocation', '"editor"');
|
||||
// Close the settings editor
|
||||
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors');
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew, 'editor');
|
||||
await terminal.assertEditorGroupCount(1);
|
||||
await terminal.assertTerminalViewHidden();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export function setup() {
|
|||
describe('detach/attach', () => {
|
||||
// https://github.com/microsoft/vscode/issues/137799
|
||||
it('should support basic reconnection', async () => {
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
// TODO: Handle passing in an actual regex, not string
|
||||
await terminal.assertTerminalGroups([
|
||||
[{ name: '.*' }]
|
||||
|
@ -41,7 +41,7 @@ export function setup() {
|
|||
});
|
||||
|
||||
it.skip('should persist buffer content', async () => {
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
// TODO: Handle passing in an actual regex, not string
|
||||
await terminal.assertTerminalGroups([
|
||||
[{ name: '.*' }]
|
||||
|
@ -71,7 +71,7 @@ export function setup() {
|
|||
|
||||
// TODO: This is currently flaky because it takes time to send over the new icon to the backend
|
||||
it.skip('should persist terminal icon', async () => {
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
// TODO: Handle passing in an actual regex, not string
|
||||
await terminal.assertTerminalGroups([
|
||||
[{ name: '.*' }]
|
||||
|
|
|
@ -24,7 +24,7 @@ export function setup() {
|
|||
|
||||
it.skip('should set the default profile to a contributed one', async () => {
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.SelectDefaultProfile, CONTRIBUTED_PROFILE_NAME);
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
await terminal.assertSingleTab({ name: CONTRIBUTED_PROFILE_NAME });
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ export function setup() {
|
|||
|
||||
it.skip('should set the default profile', async () => {
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.SelectDefaultProfile, process.platform === 'win32' ? 'PowerShell' : undefined);
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
await terminal.assertSingleTab({ name: ANY_PROFILE_NAME });
|
||||
});
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ export function setup() {
|
|||
|
||||
it('clicking the plus button should create a terminal and display the tabs view showing no split decorations', async () => {
|
||||
await terminal.runCommand(TerminalCommandId.Show);
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
await terminal.clickPlusButton();
|
||||
await terminal.assertTerminalGroups([[{}], [{}]]);
|
||||
});
|
||||
|
@ -100,14 +100,14 @@ export function setup() {
|
|||
|
||||
it('should join tabs when more than one non-split terminal', async () => {
|
||||
await terminal.runCommand(TerminalCommandId.Show);
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
await terminal.runCommand(TerminalCommandId.Join);
|
||||
await terminal.assertTerminalGroups([[{}, {}]]);
|
||||
});
|
||||
|
||||
it('should do nothing when unsplit tabs called with no splits', async () => {
|
||||
await terminal.runCommand(TerminalCommandId.Show);
|
||||
await terminal.runCommand(TerminalCommandId.CreateNew);
|
||||
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
|
||||
await terminal.assertTerminalGroups([[{}], [{}]]);
|
||||
await terminal.runCommand(TerminalCommandId.Unsplit);
|
||||
await terminal.assertTerminalGroups([[{}], [{}]]);
|
||||
|
|
Loading…
Reference in a new issue