提交 11fbd970 编写于 作者: B Benjamin Pasero

grid - introduce some simple tests for next editor part

上级 35a8792d
......@@ -63,12 +63,12 @@ export class NextEditorPart extends Part implements INextEditorGroupsService {
return this._groups.get(identifier);
}
isGroupActive(identifier: GroupIdentifier): boolean {
return this._activeGroup && this._activeGroup.id === identifier;
isGroupActive(group: NextEditorGroupView | GroupIdentifier): boolean {
return this._activeGroup && this._activeGroup === this.asGroupView(group);
}
setGroupActive(identifier: GroupIdentifier): NextEditorGroupView {
const groupView = this.getGroup(identifier);
setGroupActive(group: NextEditorGroupView | GroupIdentifier): NextEditorGroupView {
const groupView = this.asGroupView(group);
if (groupView) {
this.doSetGroupActive(groupView);
}
......@@ -76,11 +76,11 @@ export class NextEditorPart extends Part implements INextEditorGroupsService {
return groupView;
}
addGroup(fromGroup: NextEditorGroupView, direction: Direction): NextEditorGroupView {
addGroup(fromGroup: NextEditorGroupView | GroupIdentifier, direction: Direction): NextEditorGroupView {
const groupView = this.doCreateGroupView();
this.gridWidget.splitView(
this._groups.get(fromGroup.id),
this.asGroupView(fromGroup),
this.toGridViewDirection(direction),
groupView, direction === Direction.DOWN ? this.dimension.height / 2 : this.dimension.width / 2 /* TODO@grid what size? */
);
......@@ -97,6 +97,14 @@ export class NextEditorPart extends Part implements INextEditorGroupsService {
}
}
private asGroupView(group: NextEditorGroupView | GroupIdentifier): NextEditorGroupView {
if (typeof group === 'number') {
return this.getGroup(group);
}
return group;
}
private doCreateGridView(): void {
// Container
......
......@@ -46,8 +46,8 @@ export interface INextEditorGroupsService {
getGroup(identifier: GroupIdentifier): INextEditorGroup;
isGroupActive(identifier: GroupIdentifier): boolean;
setGroupActive(identifier: GroupIdentifier): INextEditorGroup;
isGroupActive(group: INextEditorGroup | GroupIdentifier): boolean;
setGroupActive(group: INextEditorGroup | GroupIdentifier): INextEditorGroup;
addGroup(fromGroup: INextEditorGroup, direction: Direction): INextEditorGroup;
addGroup(fromGroup: INextEditorGroup | GroupIdentifier, direction: Direction): INextEditorGroup;
}
\ No newline at end of file
......@@ -151,7 +151,6 @@ class TestFileEditorInput extends EditorInput implements IFileEditorInput {
return other && this.id === other.id && other instanceof TestFileEditorInput;
}
public setEncoding(encoding: string) {
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { NextEditorPart } from 'vs/workbench/browser/parts/editor2/nextEditorPart';
import { workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
import { Direction } from 'vs/workbench/services/editor/common/nextEditorGroupsService';
import { Dimension } from 'vs/base/browser/dom';
suite('editor2 tests', () => {
test('Groups basics', function () {
const instantiationService = workbenchInstantiationService();
const part = instantiationService.createInstance(NextEditorPart, 'id');
part.create(document.createElement('div'));
part.layout(new Dimension(400, 300));
let activeGroupChangeCounter = 0;
const activeGroupChangeListener = part.onDidActiveGroupChange(() => {
activeGroupChangeCounter++;
});
// always a root group
const rootGroup = part.groups[0];
assert.equal(part.groups.length, 1);
assert.ok(part.isGroupActive(rootGroup));
const rightGroup = part.addGroup(rootGroup, Direction.RIGHT);
assert.equal(part.groups.length, 2);
assert.ok(part.isGroupActive(rootGroup));
assert.equal(activeGroupChangeCounter, 0);
part.setGroupActive(rightGroup);
assert.ok(part.isGroupActive(rightGroup));
assert.equal(activeGroupChangeCounter, 1);
const downGroup = part.addGroup(rightGroup, Direction.DOWN);
assert.equal(part.groups.length, 3);
assert.ok(part.isGroupActive(rightGroup));
assert.ok(!downGroup.activeEditor);
activeGroupChangeListener.dispose();
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册