Skip to content

Commit 341bc9c

Browse files
committed
editors - add and use preferredTitleHeight for groups
1 parent 8c1015f commit 341bc9c

6 files changed

Lines changed: 53 additions & 37 deletions

File tree

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { getIEditor } from 'vs/editor/browser/editorBrowser';
1616
import { IEditorOptions } from 'vs/platform/editor/common/editor';
1717
import { IEditorService, IResourceEditorInputType } from 'vs/workbench/services/editor/common/editorService';
1818

19-
export const EDITOR_TITLE_HEIGHT = 35;
20-
2119
export interface IEditorPartCreationOptions {
2220
restorePreviousState: boolean;
2321
}
@@ -111,12 +109,6 @@ export interface IEditorGroupsAccessor {
111109
}
112110

113111
export interface IEditorGroupView extends IDisposable, ISerializableView, IEditorGroup {
114-
readonly group: EditorGroup;
115-
readonly whenRestored: Promise<void>;
116-
readonly disposed: boolean;
117-
118-
readonly isEmpty: boolean;
119-
readonly isMinimized: boolean;
120112

121113
readonly onDidFocus: Event<void>;
122114
readonly onWillDispose: Event<void>;
@@ -125,6 +117,16 @@ export interface IEditorGroupView extends IDisposable, ISerializableView, IEdito
125117
readonly onWillCloseEditor: Event<IEditorCloseEvent>;
126118
readonly onDidCloseEditor: Event<IEditorCloseEvent>;
127119

120+
readonly group: EditorGroup;
121+
readonly whenRestored: Promise<void>;
122+
123+
readonly preferredTitleHeight: number;
124+
125+
readonly isEmpty: boolean;
126+
readonly isMinimized: boolean;
127+
128+
readonly disposed: boolean;
129+
128130
setActive(isActive: boolean): void;
129131

130132
notifyIndexChanged(newIndex: number): void;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import 'vs/css!./media/editordroptarget';
77
import { LocalSelectionTransfer, DraggedEditorIdentifier, ResourcesDropHandler, DraggedEditorGroupIdentifier, DragAndDropObserver, containsDragType } from 'vs/workbench/browser/dnd';
88
import { addDisposableListener, EventType, EventHelper, isAncestor } from 'vs/base/browser/dom';
9-
import { IEditorGroupsAccessor, EDITOR_TITLE_HEIGHT, IEditorGroupView, getActiveTextEditorOptions } from 'vs/workbench/browser/parts/editor/editor';
9+
import { IEditorGroupsAccessor, IEditorGroupView, getActiveTextEditorOptions } from 'vs/workbench/browser/parts/editor/editor';
1010
import { EDITOR_DRAG_AND_DROP_BACKGROUND } from 'vs/workbench/common/theme';
1111
import { IThemeService, Themable } from 'vs/platform/theme/common/themeService';
1212
import { activeContrastBorder } from 'vs/platform/theme/common/colorRegistry';
@@ -500,10 +500,13 @@ class DropOverlay extends Themable {
500500
}
501501

502502
private getOverlayOffsetHeight(): number {
503+
504+
// With tabs and opened editors: use the area below tabs as drop target
503505
if (!this.groupView.isEmpty && this.accessor.partOptions.showTabs) {
504-
return EDITOR_TITLE_HEIGHT; // show overlay below title if group shows tabs
506+
return this.groupView.preferredTitleHeight;
505507
}
506508

509+
// Without tabs or empty group: use entire editor area as drop target
507510
return 0;
508511
}
509512

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
717717
return this._group.count === 0;
718718
}
719719

720+
get preferredTitleHeight(): number {
721+
return this.titleAreaControl.getPreferredHeight();
722+
}
723+
720724
get isMinimized(): boolean {
721725
if (!this.dimension) {
722726
return false;
@@ -1694,17 +1698,14 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
16941698
layout(width: number, height: number): void {
16951699
this.dimension = new Dimension(width, height);
16961700

1697-
// Ensure editor container gets height as CSS depending
1698-
// on the preferred height of the title control
1699-
this.editorContainer.style.height = `calc(100% - ${this.titleAreaControl.getPreferredHeight()}px)`;
1701+
// Ensure editor container gets height as CSS depending on the preferred height of the title control
1702+
const titleHeight = this.preferredTitleHeight;
1703+
const editorHeight = Math.max(0, height - titleHeight);
1704+
this.editorContainer.style.height = `${editorHeight}px`;
17001705

17011706
// Forward to controls
1702-
this.layoutTitleAreaControl(width);
1703-
this.editorControl.layout(new Dimension(this.dimension.width, Math.max(0, this.dimension.height - this.titleAreaControl.getPreferredHeight())));
1704-
}
1705-
1706-
private layoutTitleAreaControl(width: number): void {
1707-
this.titleAreaControl.layout(new Dimension(width, this.titleAreaControl.getPreferredHeight()));
1707+
this.titleAreaControl.layout(new Dimension(width, titleHeight));
1708+
this.editorControl.layout(new Dimension(width, editorHeight));
17081709
}
17091710

17101711
relayout(): void {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ResourceLabel, IResourceLabel } from 'vs/workbench/browser/labels';
1010
import { TAB_ACTIVE_FOREGROUND, TAB_UNFOCUSED_ACTIVE_FOREGROUND } from 'vs/workbench/common/theme';
1111
import { EventType as TouchEventType, GestureEvent, Gesture } from 'vs/base/browser/touch';
1212
import { addDisposableListener, EventType, EventHelper, Dimension } from 'vs/base/browser/dom';
13-
import { EDITOR_TITLE_HEIGHT } from 'vs/workbench/browser/parts/editor/editor';
1413
import { IAction } from 'vs/base/common/actions';
1514
import { CLOSE_EDITOR_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
1615
import { Color } from 'vs/base/common/color';
@@ -22,6 +21,9 @@ interface IRenderedEditorLabel {
2221
}
2322

2423
export class NoTabsTitleControl extends TitleControl {
24+
25+
private static readonly HEIGHT = 35;
26+
2527
private titleContainer: HTMLElement | undefined;
2628
private editorLabel: IResourceLabel | undefined;
2729
private activeLabel: IRenderedEditorLabel = Object.create(null);
@@ -113,10 +115,6 @@ export class NoTabsTitleControl extends TitleControl {
113115
setTimeout(() => this.quickInputService.quickAccess.show(), 50);
114116
}
115117

116-
getPreferredHeight(): number {
117-
return EDITOR_TITLE_HEIGHT;
118-
}
119-
120118
openEditor(editor: IEditorInput): void {
121119
const activeEditorChanged = this.ifActiveEditorChanged(() => this.redraw());
122120
if (!activeEditorChanged) {
@@ -317,6 +315,10 @@ export class NoTabsTitleControl extends TitleControl {
317315
return { primaryEditorActions: editorActions.primary.filter(action => action.id === CLOSE_EDITOR_COMMAND_ID), secondaryEditorActions: [] };
318316
}
319317

318+
getPreferredHeight(): number {
319+
return NoTabsTitleControl.HEIGHT;
320+
}
321+
320322
layout(dimension: Dimension): void {
321323
if (this.breadcrumbsControl) {
322324
this.breadcrumbsControl.layout(undefined);

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
3434
import { MergeGroupMode, IMergeGroupOptions, GroupsArrangement, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
3535
import { addDisposableListener, EventType, EventHelper, Dimension, scheduleAtNextAnimationFrame, findParentWithClass, clearNode } from 'vs/base/browser/dom';
3636
import { localize } from 'vs/nls';
37-
import { IEditorGroupsAccessor, IEditorGroupView, EditorServiceImpl, EDITOR_TITLE_HEIGHT } from 'vs/workbench/browser/parts/editor/editor';
37+
import { IEditorGroupsAccessor, IEditorGroupView, EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor';
3838
import { CloseOneEditorAction, UnpinEditorAction } from 'vs/workbench/browser/parts/editor/editorActions';
3939
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
4040
import { BreadcrumbsControl } from 'vs/workbench/browser/parts/editor/breadcrumbsControl';
@@ -64,12 +64,14 @@ export class TabsTitleControl extends TitleControl {
6464
large: 10
6565
};
6666

67-
private static readonly TAB_SIZES = {
67+
private static readonly TAB_WIDTH = {
6868
compact: 38,
6969
shrink: 80,
7070
fit: 120
7171
};
7272

73+
private static readonly TAB_HEIGHT = 35;
74+
7375
private titleContainer: HTMLElement | undefined;
7476
private tabsAndActionsContainer: HTMLElement | undefined;
7577
private tabsContainer: HTMLElement | undefined;
@@ -509,6 +511,11 @@ export class TabsTitleControl extends TitleControl {
509511
this.computeTabLabels();
510512
}
511513

514+
// Update tabs scrollbar sizing
515+
if (oldOptions.titleScrollbarSizing !== newOptions.titleScrollbarSizing) {
516+
this.updateTabsScrollbarSizing();
517+
}
518+
512519
// Redraw tabs when other options change
513520
if (
514521
oldOptions.labelFormat !== newOptions.labelFormat ||
@@ -521,11 +528,6 @@ export class TabsTitleControl extends TitleControl {
521528
) {
522529
this.redraw();
523530
}
524-
525-
// Udate tabs scrollbar sizing
526-
if (oldOptions.titleScrollbarSizing !== newOptions.titleScrollbarSizing) {
527-
this.updateTabsScrollbarSizing();
528-
}
529531
}
530532

531533
updateStyles(): void {
@@ -1065,10 +1067,10 @@ export class TabsTitleControl extends TitleControl {
10651067
let stickyTabWidth = 0;
10661068
switch (options.pinnedTabSizing) {
10671069
case 'compact':
1068-
stickyTabWidth = TabsTitleControl.TAB_SIZES.compact;
1070+
stickyTabWidth = TabsTitleControl.TAB_WIDTH.compact;
10691071
break;
10701072
case 'shrink':
1071-
stickyTabWidth = TabsTitleControl.TAB_SIZES.shrink;
1073+
stickyTabWidth = TabsTitleControl.TAB_WIDTH.shrink;
10721074
break;
10731075
}
10741076

@@ -1221,7 +1223,12 @@ export class TabsTitleControl extends TitleControl {
12211223
}
12221224

12231225
getPreferredHeight(): number {
1224-
return EDITOR_TITLE_HEIGHT + (this.breadcrumbsControl && !this.breadcrumbsControl.isHidden() ? BreadcrumbsControl.HEIGHT : 0);
1226+
let height = TabsTitleControl.TAB_HEIGHT;
1227+
if (this.breadcrumbsControl && !this.breadcrumbsControl.isHidden()) {
1228+
height += BreadcrumbsControl.HEIGHT;
1229+
}
1230+
1231+
return height;
12251232
}
12261233

12271234
layout(dimension: Dimension | undefined): void {
@@ -1299,10 +1306,10 @@ export class TabsTitleControl extends TitleControl {
12991306
let stickyTabWidth = 0;
13001307
switch (this.accessor.partOptions.pinnedTabSizing) {
13011308
case 'compact':
1302-
stickyTabWidth = TabsTitleControl.TAB_SIZES.compact;
1309+
stickyTabWidth = TabsTitleControl.TAB_WIDTH.compact;
13031310
break;
13041311
case 'shrink':
1305-
stickyTabWidth = TabsTitleControl.TAB_SIZES.shrink;
1312+
stickyTabWidth = TabsTitleControl.TAB_WIDTH.shrink;
13061313
break;
13071314
}
13081315

@@ -1314,7 +1321,7 @@ export class TabsTitleControl extends TitleControl {
13141321
// Special case: we have sticky tabs but the available space for showing tabs
13151322
// is little enough that we need to disable sticky tabs sticky positioning
13161323
// so that tabs can be scrolled at naturally.
1317-
if (this.group.stickyCount > 0 && availableTabsContainerWidth < TabsTitleControl.TAB_SIZES.fit) {
1324+
if (this.group.stickyCount > 0 && availableTabsContainerWidth < TabsTitleControl.TAB_WIDTH.fit) {
13181325
tabsContainer.classList.add('disable-sticky-tabs');
13191326

13201327
availableTabsContainerWidth = visibleTabsContainerWidth;

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ export class TestEditorGroupView implements IEditorGroupView {
602602
maximumWidth!: number;
603603
minimumHeight!: number;
604604
maximumHeight!: number;
605+
preferredTitleHeight!: number;
605606

606607
isEmpty = true;
607608
isMinimized = false;

0 commit comments

Comments
 (0)