Skip to content

Commit fca79ef

Browse files
swordjjjkkkbenibenjbpasero
authored
Display Tab Indexes in VSCode (microsoft#209196)
* rebase * 1.Moved the settings into options. 2.Moved tab refresh to updateOptions. 3.Simplified the code using a ternary operator. 4.Renamed the setting from 'workbench.tabIndex.enabled' to 'workbench.editor.showTabIndex'. 5.Removed some irrelevant code. * 1. add localize for tabindex display 2. change the default format to use a colon * semicolumn missing * fix tab index for untitled files * add namePrefix option for resource labels --------- Co-authored-by: Benjamin Christopher Simmonds <44439583+benibenj@users.noreply.github.com> Co-authored-by: BeniBenj <besimmonds@microsoft.com> Co-authored-by: Benjamin Pasero <benjamin.pasero@microsoft.com>
1 parent 55928d5 commit fca79ef

5 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/vs/workbench/browser/labels.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export interface IResourceLabelOptions extends IIconLabelValueOptions {
6363
*/
6464
readonly forceLabel?: boolean;
6565

66+
/**
67+
* A prefix to be added to the name of the label.
68+
*/
69+
readonly namePrefix?: string;
70+
6671
/**
6772
* Uses the provided icon instead of deriving a resource icon.
6873
*/
@@ -522,6 +527,14 @@ class ResourceLabelWidget extends IconLabel {
522527
}
523528
}
524529

530+
if (options.namePrefix) {
531+
if (typeof label.name === 'string') {
532+
label.name = options.namePrefix + label.name;
533+
} else if (Array.isArray(label.name) && label.name.length > 0) {
534+
label.name = [options.namePrefix + label.name[0], ...label.name.slice(1)];
535+
}
536+
}
537+
525538
const hasResourceChanged = this.hasResourceChanged(label);
526539
const hasPathLabelChanged = hasResourceChanged || this.hasPathLabelChanged(label);
527540
const hasFileKindChanged = this.hasFileKindChanged(options);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = {
3434
tabActionLocation: 'right',
3535
tabActionCloseVisibility: true,
3636
tabActionUnpinVisibility: true,
37+
showTabIndex: false,
3738
alwaysShowEditorActions: false,
3839
tabSizing: 'fit',
3940
tabSizingFixedMinWidth: 50,
@@ -125,6 +126,7 @@ function validateEditorPartOptions(options: IEditorPartOptions): IEditorPartOpti
125126
'highlightModifiedTabs': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['highlightModifiedTabs']),
126127
'tabActionCloseVisibility': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['tabActionCloseVisibility']),
127128
'tabActionUnpinVisibility': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['tabActionUnpinVisibility']),
129+
'showTabIndex': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['showTabIndex']),
128130
'alwaysShowEditorActions': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['alwaysShowEditorActions']),
129131
'pinnedTabsOnSeparateRow': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['pinnedTabsOnSeparateRow']),
130132
'focusRecentEditorAfterClose': new BooleanVerifier(DEFAULT_EDITOR_PART_OPTIONS['focusRecentEditorAfterClose']),

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ export class MultiEditorTabsControl extends EditorTabsControl {
778778
oldOptions.hasIcons !== newOptions.hasIcons ||
779779
oldOptions.highlightModifiedTabs !== newOptions.highlightModifiedTabs ||
780780
oldOptions.wrapTabs !== newOptions.wrapTabs ||
781+
oldOptions.showTabIndex !== newOptions.showTabIndex ||
781782
!equals(oldOptions.decorations, newOptions.decorations)
782783
) {
783784
this.redraw();
@@ -1604,6 +1605,7 @@ export class MultiEditorTabsControl extends EditorTabsControl {
16041605
// Sticky compact tabs will only show an icon if icons are enabled
16051606
// or their first character of the name otherwise
16061607
let name: string | undefined;
1608+
let namePrefix: string | undefined;
16071609
let forceLabel = false;
16081610
let fileDecorationBadges = Boolean(options.decorations?.badges);
16091611
const fileDecorationColors = Boolean(options.decorations?.colors);
@@ -1616,6 +1618,7 @@ export class MultiEditorTabsControl extends EditorTabsControl {
16161618
fileDecorationBadges = false; // not enough space when sticky tabs are compact
16171619
} else {
16181620
name = tabLabel.name;
1621+
namePrefix = options.showTabIndex ? `${this.toEditorIndex(tabIndex) + 1}: ` : undefined;
16191622
description = tabLabel.description || '';
16201623
}
16211624

@@ -1640,6 +1643,7 @@ export class MultiEditorTabsControl extends EditorTabsControl {
16401643
},
16411644
icon: editor.getIcon(),
16421645
hideIcon: options.showIcons === false,
1646+
namePrefix,
16431647
}
16441648
);
16451649

src/vs/workbench/browser/workbench.contribution.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ const registry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Con
213213
default: true,
214214
description: localize('workbench.editor.tabActionUnpinVisibility', "Controls the visibility of the tab unpin action button.")
215215
},
216+
'workbench.editor.showTabIndex': {
217+
'type': 'boolean',
218+
'default': false,
219+
'markdownDescription': localize({ comment: ['{0}, {1} will be a setting name rendered as a link'], key: 'showTabIndex' }, "When enabled, will show the tab index. This value is ignored when {0} is not set to {1}.", '`#workbench.editor.showTabs#`', '`multiple`')
220+
},
216221
'workbench.editor.tabSizing': {
217222
'type': 'string',
218223
'enum': ['fit', 'shrink', 'fixed'],

src/vs/workbench/common/editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ interface IEditorPartConfiguration {
12321232
tabActionLocation?: 'left' | 'right';
12331233
tabActionCloseVisibility?: boolean;
12341234
tabActionUnpinVisibility?: boolean;
1235+
showTabIndex?: boolean;
12351236
alwaysShowEditorActions?: boolean;
12361237
tabSizing?: 'fit' | 'shrink' | 'fixed';
12371238
tabSizingFixedMinWidth?: number;

0 commit comments

Comments
 (0)