Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed tab sizing: restore tab widths when the last tab is closed #183188

Merged
merged 3 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/vs/workbench/browser/parts/editor/editorGroupView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,30 +1335,29 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}

private doCloseEditor(editor: EditorInput, focusNext = (this.accessor.activeGroup === this), internalOptions?: IInternalEditorCloseOptions): void {
let index: number | undefined;

// Forward to title control unless skipped via internal options
if (!internalOptions?.skipTitleUpdate) {
this.titleAreaControl.beforeCloseEditor(editor, index);
this.titleAreaControl.beforeCloseEditor(editor);
}

// Closing the active editor of the group is a bit more work
if (this.model.isActive(editor)) {
index = this.doCloseActiveEditor(focusNext, internalOptions);
this.doCloseActiveEditor(focusNext, internalOptions);
}

// Closing inactive editor is just a model update
else {
index = this.doCloseInactiveEditor(editor, internalOptions);
this.doCloseInactiveEditor(editor, internalOptions);
}

// Forward to title control unless skipped via internal options
if (!internalOptions?.skipTitleUpdate) {
this.titleAreaControl.closeEditor(editor, index);
this.titleAreaControl.closeEditor(editor);
}
}

private doCloseActiveEditor(focusNext = (this.accessor.activeGroup === this), internalOptions?: IInternalEditorCloseOptions): number | undefined {
private doCloseActiveEditor(focusNext = (this.accessor.activeGroup === this), internalOptions?: IInternalEditorCloseOptions): void {
const editorToClose = this.activeEditor;
const restoreFocus = this.shouldRestoreFocus(this.element);

Expand All @@ -1383,9 +1382,8 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
}

// Update model
let index: number | undefined = undefined;
if (editorToClose) {
index = this.model.closeEditor(editorToClose, internalOptions?.context)?.editorIndex;
this.model.closeEditor(editorToClose, internalOptions?.context);
}

// Open next active if there are more to show
Expand Down Expand Up @@ -1437,8 +1435,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this.accessor.removeGroup(this);
}
}

return index;
}

private shouldRestoreFocus(target: Element): boolean {
Expand All @@ -1452,10 +1448,10 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
return isAncestor(activeElement, target);
}

private doCloseInactiveEditor(editor: EditorInput, internalOptions?: IInternalEditorCloseOptions): number | undefined {
private doCloseInactiveEditor(editor: EditorInput, internalOptions?: IInternalEditorCloseOptions): void {

// Update model
return this.model.closeEditor(editor, internalOptions?.context)?.editorIndex;
this.model.closeEditor(editor, internalOptions?.context);
}

private async handleCloseConfirmation(editors: EditorInput[]): Promise<boolean /* veto */> {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/noTabsTitleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ export class NoTabsTitleControl extends TitleControl {
}
}

beforeCloseEditor(): void {
beforeCloseEditor(editor: EditorInput): void {
// Nothing to do before closing an editor
}

closeEditor(editor: EditorInput, index: number | undefined): void {
closeEditor(editor: EditorInput): void {
this.ifActiveEditorChanged(() => this.redraw());
}

Expand Down
15 changes: 8 additions & 7 deletions src/vs/workbench/browser/parts/editor/tabsTitleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,27 +557,28 @@ export class TabsTitleControl extends TitleControl {
labelA.ariaLabel === labelB.ariaLabel;
}

beforeCloseEditor(): void {
beforeCloseEditor(editor: EditorInput): void {

// Fix tabs width if the mouse is over tabs and
// before closing a tab when tab sizing is 'fixed'.
// Fix tabs width if the mouse is over tabs and before closing
// a tab (except the last tab) when tab sizing is 'fixed'.
// This helps keeping the close button stable under
// the mouse and allows for rapid closing of tabs.

if (this.isMouseOverTabs && this.accessor.partOptions.tabSizing === 'fixed') {
this.updateTabsFixedWidth(true);
const closingLastTab = this.group.isLast(editor);
this.updateTabsFixedWidth(!closingLastTab);
}
}

closeEditor(editor: EditorInput, index: number | undefined): void {
this.handleClosedEditors(index);
closeEditor(editor: EditorInput): void {
this.handleClosedEditors();
}

closeEditors(editors: EditorInput[]): void {
this.handleClosedEditors();
}

private handleClosedEditors(index?: number): void {
private handleClosedEditors(): void {

// There are tabs to show
if (this.group.activeEditor) {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/browser/parts/editor/titleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ export abstract class TitleControl extends Themable {

abstract openEditors(editors: EditorInput[]): void;

abstract beforeCloseEditor(editor: EditorInput, index: number | undefined): void;
abstract beforeCloseEditor(editor: EditorInput): void;

abstract closeEditor(editor: EditorInput, index: number | undefined): void;
abstract closeEditor(editor: EditorInput): void;

abstract closeEditors(editors: EditorInput[]): void;

Expand Down