Skip to content

Commit fc063a5

Browse files
fixed tab sizing: restore tab widths when the last tab is closed (microsoft#183188)
* restore tab widths when the last tab is closed * Remove unused editor index Nothing was using the index and beforeCloseEditor could never get anything but undefined anyway. * 💄 --------- Co-authored-by: Benjamin Pasero <[email protected]>
1 parent eebf235 commit fc063a5

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

src/vs/workbench/browser/parts/editor/editorGroupView.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,30 +1335,29 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
13351335
}
13361336

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

13401339
// Forward to title control unless skipped via internal options
13411340
if (!internalOptions?.skipTitleUpdate) {
1342-
this.titleAreaControl.beforeCloseEditor(editor, index);
1341+
this.titleAreaControl.beforeCloseEditor(editor);
13431342
}
13441343

13451344
// Closing the active editor of the group is a bit more work
13461345
if (this.model.isActive(editor)) {
1347-
index = this.doCloseActiveEditor(focusNext, internalOptions);
1346+
this.doCloseActiveEditor(focusNext, internalOptions);
13481347
}
13491348

13501349
// Closing inactive editor is just a model update
13511350
else {
1352-
index = this.doCloseInactiveEditor(editor, internalOptions);
1351+
this.doCloseInactiveEditor(editor, internalOptions);
13531352
}
13541353

13551354
// Forward to title control unless skipped via internal options
13561355
if (!internalOptions?.skipTitleUpdate) {
1357-
this.titleAreaControl.closeEditor(editor, index);
1356+
this.titleAreaControl.closeEditor(editor);
13581357
}
13591358
}
13601359

1361-
private doCloseActiveEditor(focusNext = (this.accessor.activeGroup === this), internalOptions?: IInternalEditorCloseOptions): number | undefined {
1360+
private doCloseActiveEditor(focusNext = (this.accessor.activeGroup === this), internalOptions?: IInternalEditorCloseOptions): void {
13621361
const editorToClose = this.activeEditor;
13631362
const restoreFocus = this.shouldRestoreFocus(this.element);
13641363

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

13851384
// Update model
1386-
let index: number | undefined = undefined;
13871385
if (editorToClose) {
1388-
index = this.model.closeEditor(editorToClose, internalOptions?.context)?.editorIndex;
1386+
this.model.closeEditor(editorToClose, internalOptions?.context);
13891387
}
13901388

13911389
// Open next active if there are more to show
@@ -1437,8 +1435,6 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
14371435
this.accessor.removeGroup(this);
14381436
}
14391437
}
1440-
1441-
return index;
14421438
}
14431439

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

1455-
private doCloseInactiveEditor(editor: EditorInput, internalOptions?: IInternalEditorCloseOptions): number | undefined {
1451+
private doCloseInactiveEditor(editor: EditorInput, internalOptions?: IInternalEditorCloseOptions): void {
14561452

14571453
// Update model
1458-
return this.model.closeEditor(editor, internalOptions?.context)?.editorIndex;
1454+
this.model.closeEditor(editor, internalOptions?.context);
14591455
}
14601456

14611457
private async handleCloseConfirmation(editors: EditorInput[]): Promise<boolean /* veto */> {

src/vs/workbench/browser/parts/editor/noTabsTitleControl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ export class NoTabsTitleControl extends TitleControl {
143143
}
144144
}
145145

146-
beforeCloseEditor(): void {
146+
beforeCloseEditor(editor: EditorInput): void {
147147
// Nothing to do before closing an editor
148148
}
149149

150-
closeEditor(editor: EditorInput, index: number | undefined): void {
150+
closeEditor(editor: EditorInput): void {
151151
this.ifActiveEditorChanged(() => this.redraw());
152152
}
153153

src/vs/workbench/browser/parts/editor/tabsTitleControl.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,27 +557,28 @@ export class TabsTitleControl extends TitleControl {
557557
labelA.ariaLabel === labelB.ariaLabel;
558558
}
559559

560-
beforeCloseEditor(): void {
560+
beforeCloseEditor(editor: EditorInput): void {
561561

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

567567
if (this.isMouseOverTabs && this.accessor.partOptions.tabSizing === 'fixed') {
568-
this.updateTabsFixedWidth(true);
568+
const closingLastTab = this.group.isLast(editor);
569+
this.updateTabsFixedWidth(!closingLastTab);
569570
}
570571
}
571572

572-
closeEditor(editor: EditorInput, index: number | undefined): void {
573-
this.handleClosedEditors(index);
573+
closeEditor(editor: EditorInput): void {
574+
this.handleClosedEditors();
574575
}
575576

576577
closeEditors(editors: EditorInput[]): void {
577578
this.handleClosedEditors();
578579
}
579580

580-
private handleClosedEditors(index?: number): void {
581+
private handleClosedEditors(): void {
581582

582583
// There are tabs to show
583584
if (this.group.activeEditor) {

src/vs/workbench/browser/parts/editor/titleControl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,9 @@ export abstract class TitleControl extends Themable {
418418

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

421-
abstract beforeCloseEditor(editor: EditorInput, index: number | undefined): void;
421+
abstract beforeCloseEditor(editor: EditorInput): void;
422422

423-
abstract closeEditor(editor: EditorInput, index: number | undefined): void;
423+
abstract closeEditor(editor: EditorInput): void;
424424

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

0 commit comments

Comments
 (0)