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

Add setting for tab closing order #66635

Merged
merged 7 commits into from
Jan 18, 2019
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
1 change: 1 addition & 0 deletions src/vs/workbench/browser/parts/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const DEFAULT_EDITOR_PART_OPTIONS: IEditorPartOptions = {
highlightModifiedTabs: false,
tabCloseButton: 'right',
tabSizing: 'fit',
closeTabsInMRUOrder: true,
showIcons: true,
enablePreview: true,
openPositioning: 'right',
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ export interface IWorkbenchEditorPartConfiguration {
highlightModifiedTabs?: boolean;
tabCloseButton?: 'left' | 'right' | 'off';
tabSizing?: 'fit' | 'shrink';
closeTabsInMRUOrder?: boolean;
showIcons?: boolean;
enablePreview?: boolean;
enablePreviewFromQuickOpen?: boolean;
Expand Down
18 changes: 17 additions & 1 deletion src/vs/workbench/common/editor/editorGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class EditorGroup extends Disposable {
private active: EditorInput | null; // editor in active state

private editorOpenPositioning: 'left' | 'right' | 'first' | 'last';
private closeTabsInMRUOrder: boolean;

constructor(
labelOrSerializedGroup: ISerializedEditorGroup,
Expand All @@ -122,6 +123,7 @@ export class EditorGroup extends Disposable {

private onConfigurationUpdated(event?: IConfigurationChangeEvent): void {
this.editorOpenPositioning = this.configurationService.getValue('workbench.editor.openPositioning');
this.closeTabsInMRUOrder = this.configurationService.getValue('workbench.editor.closeTabsInMRUOrder');
}

get id(): GroupIdentifier {
Expand Down Expand Up @@ -332,7 +334,21 @@ export class EditorGroup extends Disposable {

// More than one editor
if (this.mru.length > 1) {
this.setActive(this.mru[1]); // active editor is always first in MRU, so pick second editor after as new active

let newActive: EditorInput;

if (this.closeTabsInMRUOrder) {
newActive = this.mru[1]; // active editor is always first in MRU, so pick second editor after as new active
}
else {
if (index === this.editors.length - 1) {
newActive = this.editors[index - 1]; // last editor is closed, pick previous as new active
}
else {
newActive = this.editors[index + 1]; // pick next editor as new active
}
}
this.setActive(newActive);
}

// One Editor
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ configurationRegistry.registerConfiguration({
],
'description': nls.localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'tabSizing' }, "Controls the sizing of editor tabs.")
},
'workbench.editor.closeTabsInMRUOrder': {
'type': 'boolean',
'description': nls.localize('closeTabsInMRUOrder', "Controls whether tabs are closed in most recently used order."),
'default': true
},
'workbench.editor.showIcons': {
'type': 'boolean',
'description': nls.localize('showIcons', "Controls whether opened editors should show with an icon or not. This requires an icon theme to be enabled as well."),
Expand Down
60 changes: 59 additions & 1 deletion src/vs/workbench/test/common/editor/editorGroups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function inst(): IInstantiationService {
inst.stub(ITelemetryService, NullTelemetryService);

const config = new TestConfigurationService();
config.setUserConfiguration('workbench', { editor: { openPositioning: 'right' } });
config.setUserConfiguration('workbench', { editor: { openPositioning: 'right', closeTabsInMRUOrder: true } });
inst.stub(IConfigurationService, config);

return inst;
Expand Down Expand Up @@ -645,6 +645,64 @@ suite('Workbench editor groups', () => {
assert.equal(group.count, 0);
});

test('Multiple Editors - closing picks next to the right', function () {
let inst = new TestInstantiationService();
inst.stub(IStorageService, new TestStorageService());
inst.stub(ILifecycleService, new TestLifecycleService());
inst.stub(IWorkspaceContextService, new TestContextService());
inst.stub(ITelemetryService, NullTelemetryService);

const config = new TestConfigurationService();
config.setUserConfiguration('workbench', { editor: { closeTabsInMRUOrder: false } });
inst.stub(IConfigurationService, config);

const group = inst.createInstance(EditorGroup);
const events = groupListener(group);

const input1 = input();
const input2 = input();
const input3 = input();
const input4 = input();
const input5 = input();

group.openEditor(input1, { pinned: true, active: true });
group.openEditor(input2, { pinned: true, active: true });
group.openEditor(input3, { pinned: true, active: true });
group.openEditor(input4, { pinned: true, active: true });
group.openEditor(input5, { pinned: true, active: true });

assert.equal(group.activeEditor, input5);
assert.equal(group.getEditors(true)[0], input5);
assert.equal(group.count, 5);

group.closeEditor(input5);
assert.equal(group.activeEditor, input4);
assert.equal(events.activated[5], input4);
assert.equal(group.count, 4);

group.setActive(input1);
group.closeEditor(input1);

assert.equal(group.activeEditor, input2);
assert.equal(group.count, 3);

group.setActive(input3);
group.closeEditor(input3);

assert.equal(group.activeEditor, input4);
assert.equal(group.count, 2);

group.closeEditor(input4);

assert.equal(group.activeEditor, input2);
assert.equal(group.count, 1);

group.closeEditor(input2);

assert.ok(!group.activeEditor);
assert.equal(group.count, 0);
});

test('Multiple Editors - move editor', function () {
const group = createGroup();
const events = groupListener(group);
Expand Down