提交 f85db576 编写于 作者: S SimonEggert 提交者: Benjamin Pasero

Add setting for tab closing order (#66635)

* Add tabClosingOrder, set default mru and use setting to focus next tab

* Change domAction name

* Fix formatting

* Use mru behavior if no tabClosingOrder is specified

* Add tests for ltr and rtl tabClosingOrder

* Create group with changed settings to fix tests

* Change setting to boolean, remove unneeded code changes, avoid multiple method-calls,  only calculate setting when config changes, adjust tests
上级 c037ce76
......@@ -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',
......
......@@ -941,6 +941,7 @@ export interface IWorkbenchEditorPartConfiguration {
highlightModifiedTabs?: boolean;
tabCloseButton?: 'left' | 'right' | 'off';
tabSizing?: 'fit' | 'shrink';
closeTabsInMRUOrder?: boolean;
showIcons?: boolean;
enablePreview?: boolean;
enablePreviewFromQuickOpen?: boolean;
......
......@@ -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,
......@@ -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 {
......@@ -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
......
......@@ -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."),
......
......@@ -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;
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册