Skip to content

Commit e6400e7

Browse files
committed
Put close icons at the start of the tab label by default on macOS
Add a new window.tabCloseIconPlacement preference for whether to present the Close (X) icon in tab titles on the left or the right of the tab. Default to the left on macOS platform in conformity with the OS's native tab controls. Fixes eclipse-theia/theia-ide#460 Signed-off-by: Christian W. Damus <[email protected]>
1 parent 14908a2 commit e6400e7

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

packages/core/src/browser/core-preferences.ts

+13
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ export const corePreferenceSchema: PreferenceSchema = {
121121
scope: 'application',
122122
markdownDescription: nls.localizeByDefault('Separator used by {0}.', '`#window.title#`')
123123
},
124+
'window.tabCloseIconPlacement': {
125+
type: 'string',
126+
enum: ['end', 'start'],
127+
enumDescriptions: [
128+
nls.localizeByDefault('Place the close icon at the end of the label. In left-to-right languages, this is the right side of the tab.'),
129+
nls.localizeByDefault('Place the close icon at the start of the label. In left-to-right languages, this is the left side of the tab.'),
130+
],
131+
default: isOSX ? 'start' : 'end',
132+
scope: 'application',
133+
description: nls.localizeByDefault('Place the close icons on tab titles at the start or end of the tab. The default is the host OS convention.'),
134+
included: isOSX
135+
},
124136
'window.secondaryWindowPlacement': {
125137
type: 'string',
126138
enum: ['originalSize', 'halfWidth', 'fullSize'],
@@ -305,6 +317,7 @@ export interface CoreConfiguration {
305317
'window.menuBarVisibility': 'classic' | 'visible' | 'hidden' | 'compact';
306318
'window.title': string;
307319
'window.titleSeparator': string;
320+
'window.tabCloseIconPlacement': 'end' | 'start';
308321
'workbench.list.openMode': 'singleClick' | 'doubleClick';
309322
'workbench.commandPalette.history': number;
310323
'workbench.editor.highlightModifiedTabs': boolean;

packages/core/src/browser/shell/tab-bars.ts

+25-13
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export class TabBarRenderer extends TabBar.Renderer {
118118
}
119119
}));
120120
}
121+
if (this.corePreferences) {
122+
this.toDispose.push(this.corePreferences.onPreferenceChanged(event => {
123+
if (event.preferenceName === 'window.tabCloseIconPlacement' && this._tabBar) {
124+
this._tabBar.update();
125+
}
126+
}));
127+
}
121128
}
122129

123130
dispose(): void {
@@ -175,6 +182,23 @@ export class TabBarRenderer extends TabBar.Renderer {
175182
onmouseenter: this.handleMouseEnterEvent
176183
};
177184

185+
const tabCloseIconStart = this.corePreferences?.['window.tabCloseIconPlacement'] === 'start';
186+
const tabLabel = h.div(
187+
{ className: 'theia-tab-icon-label' },
188+
this.renderIcon(data, isInSidePanel),
189+
this.renderLabel(data, isInSidePanel),
190+
this.renderTailDecorations(data, isInSidePanel),
191+
this.renderBadge(data, isInSidePanel),
192+
this.renderLock(data, isInSidePanel)
193+
);
194+
const tabCloseIcon = h.div({
195+
className: `p-TabBar-tabCloseIcon action-label ${tabCloseIconStart ? 'start' : ''}`,
196+
title: closeIconTitle,
197+
onclick: this.handleCloseClickEvent
198+
});
199+
200+
const tabContents = tabCloseIconStart ? [tabCloseIcon, tabLabel] : [tabLabel, tabCloseIcon];
201+
178202
return h.li(
179203
{
180204
...hover,
@@ -186,19 +210,7 @@ export class TabBarRenderer extends TabBar.Renderer {
186210
e.preventDefault();
187211
}
188212
},
189-
h.div(
190-
{ className: 'theia-tab-icon-label' },
191-
this.renderIcon(data, isInSidePanel),
192-
this.renderLabel(data, isInSidePanel),
193-
this.renderTailDecorations(data, isInSidePanel),
194-
this.renderBadge(data, isInSidePanel),
195-
this.renderLock(data, isInSidePanel)
196-
),
197-
h.div({
198-
className: 'p-TabBar-tabCloseIcon action-label',
199-
title: closeIconTitle,
200-
onclick: this.handleCloseClickEvent
201-
})
213+
...tabContents
202214
);
203215
}
204216

packages/core/src/browser/style/tabs.css

+6
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@
237237
-ms-user-select: none;
238238
}
239239

240+
.p-TabBar.theia-app-centers .p-TabBar-tab.p-mod-closable>.p-TabBar-tabCloseIcon.start,
241+
.p-TabBar.theia-app-centers .p-TabBar-tab.theia-mod-pinned>.p-TabBar-tabCloseIcon.start {
242+
margin-left: inherit;
243+
margin-right: 4px;
244+
}
245+
240246
.p-TabBar.theia-app-centers.dynamic-tabs .p-TabBar-tab.p-mod-closable>.p-TabBar-tabCloseIcon,
241247
.p-TabBar.theia-app-centers.dynamic-tabs .p-TabBar-tab.theia-mod-pinned>.p-TabBar-tabCloseIcon {
242248
/* hide close icon for dynamic tabs strategy*/

0 commit comments

Comments
 (0)