save tabs width in vertical and horizontal terminal panel positions (#123516)

This commit is contained in:
Megan Rogge 2021-05-10 19:05:54 -05:00 committed by GitHub
parent 4eef854ab4
commit 6c9f17152c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 20 deletions

View file

@ -17,6 +17,7 @@ import type { Unicode11Addon as XTermUnicode11Addon } from 'xterm-addon-unicode1
import type { WebglAddon as XTermWebglAddon } from 'xterm-addon-webgl';
import { ITerminalStatusList } from 'vs/workbench/contrib/terminal/browser/terminalStatusList';
import { ICompleteTerminalConfiguration } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel';
import { Orientation } from 'vs/base/browser/ui/splitview/splitview';
export const ITerminalService = createDecorator<ITerminalService>('terminalService');
export const ITerminalInstanceService = createDecorator<ITerminalInstanceService>('terminalInstanceService');
@ -115,7 +116,7 @@ export interface ITerminalService {
onDidRegisterProcessSupport: Event<void>;
onDidChangeConnectionState: Event<void>;
onDidChangeAvailableProfiles: Event<ITerminalProfile[]>;
onPanelMovedToSide: Event<void>;
onPanelOrientationChanged: Event<Orientation>;
/**
* Creates a terminal.

View file

@ -245,8 +245,8 @@ export class TerminalGroup extends Disposable implements ITerminalGroup {
public readonly onDisposed: Event<ITerminalGroup> = this._onDisposed.event;
private readonly _onInstancesChanged: Emitter<void> = this._register(new Emitter<void>());
readonly onInstancesChanged: Event<void> = this._onInstancesChanged.event;
private readonly _onPanelMovedToSide = new Emitter<void>();
get onPanelMovedToSide(): Event<void> { return this._onPanelMovedToSide.event; }
private readonly _onPanelOrientationChanged = new Emitter<Orientation>();
get onPanelOrientationChanged(): Event<Orientation> { return this._onPanelOrientationChanged.event; }
constructor(
private _container: HTMLElement | undefined,
shellLaunchConfigOrInstance: IShellLaunchConfig | ITerminalInstance | undefined,
@ -263,6 +263,7 @@ export class TerminalGroup extends Disposable implements ITerminalGroup {
if (this._container) {
this.attachToElement(this._container);
}
this._onPanelOrientationChanged.fire(this._terminalLocation === ViewContainerLocation.Panel && this._panelPosition === Position.BOTTOM ? Orientation.HORIZONTAL : Orientation.VERTICAL);
}
addInstance(shellLaunchConfigOrInstance: IShellLaunchConfig | ITerminalInstance): void {
@ -465,15 +466,13 @@ export class TerminalGroup extends Disposable implements ITerminalGroup {
this._splitPaneContainer.setOrientation(newOrientation);
this._panelPosition = newPanelPosition;
this._terminalLocation = newTerminalLocation;
this._onPanelOrientationChanged.fire(this._splitPaneContainer.orientation);
}
this._splitPaneContainer.layout(width, height);
if (this._initialRelativeSizes && height > 0 && width > 0) {
this.resizePanes(this._initialRelativeSizes);
this._initialRelativeSizes = undefined;
}
if (terminalPositionChanged && this._splitPaneContainer.orientation === Orientation.VERTICAL) {
this._onPanelMovedToSide.fire();
}
}
}

View file

@ -40,6 +40,7 @@ import { ILabelService } from 'vs/platform/label/common/label';
import { Schemas } from 'vs/base/common/network';
import { VirtualWorkspaceContext } from 'vs/workbench/browser/contextkeys';
import { formatMessageForTerminal } from 'vs/workbench/contrib/terminal/common/terminalStrings';
import { Orientation } from 'vs/base/browser/ui/sash/sash';
export class TerminalService implements ITerminalService {
declare _serviceBrand: undefined;
@ -119,8 +120,8 @@ export class TerminalService implements ITerminalService {
get onDidChangeConnectionState(): Event<void> { return this._onDidChangeConnectionState.event; }
private readonly _onDidChangeAvailableProfiles = new Emitter<ITerminalProfile[]>();
get onDidChangeAvailableProfiles(): Event<ITerminalProfile[]> { return this._onDidChangeAvailableProfiles.event; }
private readonly _onPanelMovedToSide = new Emitter<void>();
get onPanelMovedToSide(): Event<void> { return this._onPanelMovedToSide.event; }
private readonly _onPanelOrientationChanged = new Emitter<Orientation>();
get onPanelOrientationChanged(): Event<Orientation> { return this._onPanelOrientationChanged.event; }
constructor(
@IContextKeyService private _contextKeyService: IContextKeyService,
@ -959,7 +960,7 @@ export class TerminalService implements ITerminalService {
const terminalGroup = this._instantiationService.createInstance(TerminalGroup, this._terminalContainer, shellLaunchConfig);
this._terminalGroups.push(terminalGroup);
terminalGroup.onPanelMovedToSide(() => this._onPanelMovedToSide.fire());
terminalGroup.onPanelOrientationChanged((orientation) => this._onPanelOrientationChanged.fire(orientation));
const instance = terminalGroup.terminalInstances[0];

View file

@ -30,7 +30,8 @@ import { localize } from 'vs/nls';
const $ = dom.$;
const FIND_FOCUS_CLASS = 'find-focused';
const TABS_WIDGET_WIDTH_KEY = 'tabs-widget-width';
const TABS_WIDGET_WIDTH_HORIZONTAL_KEY = 'tabs-widget-width-horizontal';
const TABS_WIDGET_WIDTH_VERTICAL_KEY = 'tabs-widget-width-vertical';
const MAX_TABS_WIDGET_WIDTH = 500;
const STATUS_ICON_WIDTH = 30;
const SPLIT_ANNOTATION_WIDTH = 30;
@ -66,6 +67,8 @@ export class TerminalTabbedView extends Disposable {
private _terminalIsTabsNarrowContextKey: IContextKey<boolean>;
private _terminalTabsFocusContextKey: IContextKey<boolean>;
private _panelOrientation: Orientation | undefined;
constructor(
parentElement: HTMLElement,
@ITerminalService private readonly _terminalService: ITerminalService,
@ -134,16 +137,13 @@ export class TerminalTabbedView extends Disposable {
this._attachEventListeners(parentElement, this._terminalContainer);
this._terminalService.onPanelOrientationChanged((orientation) => {
this._panelOrientation = orientation;
});
this._splitView = new SplitView(parentElement, { orientation: Orientation.HORIZONTAL, proportionalLayout: false });
this._setupSplitView();
this._terminalService.onPanelMovedToSide(() => {
try {
this._updateWidgetWidth(MIN_TABS_WIDGET_WIDTH);
} catch (e) {
}
});
}
private _shouldShowTabs(): boolean {
@ -172,9 +172,13 @@ export class TerminalTabbedView extends Disposable {
}
private _getLastWidgetWidth(): number {
const storedValue = this._storageService.get(TABS_WIDGET_WIDTH_KEY, StorageScope.WORKSPACE);
const widthKey = this._panelOrientation === Orientation.VERTICAL ? TABS_WIDGET_WIDTH_VERTICAL_KEY : TABS_WIDGET_WIDTH_HORIZONTAL_KEY;
const storedValue = this._storageService.get(widthKey, StorageScope.WORKSPACE);
if (!storedValue || !parseInt(storedValue)) {
return DEFAULT_TABS_WIDGET_WIDTH;
// we want to use the min width by default for the vertical orientation bc
// there is such a limited width for the terminal panel to begin w there.
return this._panelOrientation === Orientation.VERTICAL ? MIN_TABS_WIDGET_WIDTH : DEFAULT_TABS_WIDGET_WIDTH;
}
return parseInt(storedValue);
}
@ -226,7 +230,8 @@ export class TerminalTabbedView extends Disposable {
this._splitView.resizeView(this._tabTreeIndex, width);
}
this._rerenderTabs();
this._storageService.store(TABS_WIDGET_WIDTH_KEY, width, StorageScope.WORKSPACE, StorageTarget.USER);
const widthKey = this._panelOrientation === Orientation.VERTICAL ? TABS_WIDGET_WIDTH_VERTICAL_KEY : TABS_WIDGET_WIDTH_HORIZONTAL_KEY;
this._storageService.store(widthKey, width, StorageScope.WORKSPACE, StorageTarget.USER);
}
private _setupSplitView(): void {