mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 11:08:31 -05:00
Merge from vscode 7653d836944892f83ce9e1f95c1204bafa1aec31
This commit is contained in:
@@ -41,15 +41,20 @@ suite('NotebookConcatDocument', function () {
|
||||
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
|
||||
async $registerNotebookProvider() { }
|
||||
async $unregisterNotebookProvider() { }
|
||||
async $createNotebookDocument() { }
|
||||
});
|
||||
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
|
||||
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
|
||||
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors);
|
||||
let reg = extHostNotebooks.registerNotebookProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookProvider>() {
|
||||
async resolveNotebook() { }
|
||||
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
|
||||
// async openNotebook() { }
|
||||
});
|
||||
await extHostNotebooks.$acceptDocumentAndEditorsDelta({
|
||||
addedDocuments: [{
|
||||
handle: 0,
|
||||
uri: notebookUri,
|
||||
viewType: 'test'
|
||||
}]
|
||||
});
|
||||
await extHostNotebooks.$resolveNotebook('test', notebookUri);
|
||||
extHostNotebooks.$acceptModelChanged(notebookUri, {
|
||||
kind: NotebookCellsChangeType.ModelChange,
|
||||
versionId: 0,
|
||||
@@ -62,7 +67,7 @@ suite('NotebookConcatDocument', function () {
|
||||
outputs: [],
|
||||
}]]]
|
||||
});
|
||||
await extHostNotebooks.$updateActiveEditor('test', notebookUri);
|
||||
await extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: notebookUri });
|
||||
|
||||
notebook = extHostNotebooks.activeNotebookDocument!;
|
||||
|
||||
|
||||
@@ -41,6 +41,38 @@ function createGroup(serialized?: ISerializedEditorGroup): EditorGroup {
|
||||
return inst().createInstance(EditorGroup, serialized);
|
||||
}
|
||||
|
||||
function closeAllEditors(group: EditorGroup): void {
|
||||
for (const editor of group.getEditors(EditorsOrder.SEQUENTIAL)) {
|
||||
group.closeEditor(editor, false);
|
||||
}
|
||||
}
|
||||
|
||||
function closeEditors(group: EditorGroup, except: EditorInput, direction?: CloseDirection): void {
|
||||
const index = group.indexOf(except);
|
||||
if (index === -1) {
|
||||
return; // not found
|
||||
}
|
||||
|
||||
// Close to the left
|
||||
if (direction === CloseDirection.LEFT) {
|
||||
for (let i = index - 1; i >= 0; i--) {
|
||||
group.closeEditor(group.getEditorByIndex(i)!);
|
||||
}
|
||||
}
|
||||
|
||||
// Close to the right
|
||||
else if (direction === CloseDirection.RIGHT) {
|
||||
for (let i = group.getEditors(EditorsOrder.SEQUENTIAL).length - 1; i > index; i--) {
|
||||
group.closeEditor(group.getEditorByIndex(i)!);
|
||||
}
|
||||
}
|
||||
|
||||
// Both directions
|
||||
else {
|
||||
group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).filter(editor => !editor.matches(except)).forEach(editor => group.closeEditor(editor));
|
||||
}
|
||||
}
|
||||
|
||||
interface GroupEvents {
|
||||
opened: EditorInput[];
|
||||
activated: EditorInput[];
|
||||
@@ -206,13 +238,25 @@ suite('Workbench editor groups', () => {
|
||||
group.openEditor(input2, { pinned: true, active: true });
|
||||
group.openEditor(input3, { pinned: false, active: true });
|
||||
|
||||
// Sticky
|
||||
group.stick(input2);
|
||||
assert.ok(group.isSticky(input2));
|
||||
|
||||
const clone = group.clone();
|
||||
assert.notEqual(group.id, clone.id);
|
||||
assert.equal(clone.count, 3);
|
||||
|
||||
assert.equal(clone.isPinned(input1), true);
|
||||
assert.equal(clone.isActive(input1), false);
|
||||
assert.equal(clone.isSticky(input1), false);
|
||||
|
||||
assert.equal(clone.isPinned(input2), true);
|
||||
assert.equal(clone.isActive(input2), false);
|
||||
assert.equal(clone.isSticky(input2), true);
|
||||
|
||||
assert.equal(clone.isPinned(input3), false);
|
||||
assert.equal(clone.isActive(input3), true);
|
||||
assert.equal(clone.isSticky(input3), false);
|
||||
});
|
||||
|
||||
test('contains()', function () {
|
||||
@@ -346,6 +390,61 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 0);
|
||||
});
|
||||
|
||||
test('group serialization (sticky editor)', function () {
|
||||
inst().invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
|
||||
const group = createGroup();
|
||||
|
||||
const input1 = input();
|
||||
const input2 = input();
|
||||
const input3 = input();
|
||||
|
||||
// Case 1: inputs can be serialized and deserialized
|
||||
|
||||
group.openEditor(input1, { pinned: true, active: true });
|
||||
group.openEditor(input2, { pinned: true, active: true });
|
||||
group.openEditor(input3, { pinned: false, active: true });
|
||||
|
||||
group.stick(input2);
|
||||
assert.ok(group.isSticky(input2));
|
||||
|
||||
let deserialized = createGroup(group.serialize());
|
||||
assert.equal(group.id, deserialized.id);
|
||||
assert.equal(deserialized.count, 3);
|
||||
|
||||
assert.equal(deserialized.isPinned(input1), true);
|
||||
assert.equal(deserialized.isActive(input1), false);
|
||||
assert.equal(deserialized.isSticky(input1), false);
|
||||
|
||||
assert.equal(deserialized.isPinned(input2), true);
|
||||
assert.equal(deserialized.isActive(input2), false);
|
||||
assert.equal(deserialized.isSticky(input2), true);
|
||||
|
||||
assert.equal(deserialized.isPinned(input3), false);
|
||||
assert.equal(deserialized.isActive(input3), true);
|
||||
assert.equal(deserialized.isSticky(input3), false);
|
||||
|
||||
// Case 2: inputs cannot be serialized
|
||||
TestEditorInputFactory.disableSerialize = true;
|
||||
|
||||
deserialized = createGroup(group.serialize());
|
||||
assert.equal(group.id, deserialized.id);
|
||||
assert.equal(deserialized.count, 0);
|
||||
assert.equal(deserialized.stickyCount, 0);
|
||||
assert.equal(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 0);
|
||||
assert.equal(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 0);
|
||||
|
||||
// Case 3: inputs cannot be deserialized
|
||||
TestEditorInputFactory.disableSerialize = false;
|
||||
TestEditorInputFactory.disableDeserialize = true;
|
||||
|
||||
deserialized = createGroup(group.serialize());
|
||||
assert.equal(group.id, deserialized.id);
|
||||
assert.equal(deserialized.count, 0);
|
||||
assert.equal(deserialized.stickyCount, 0);
|
||||
assert.equal(deserialized.getEditors(EditorsOrder.SEQUENTIAL).length, 0);
|
||||
assert.equal(deserialized.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 0);
|
||||
});
|
||||
|
||||
test('One Editor', function () {
|
||||
const group = createGroup();
|
||||
const events = groupListener(group);
|
||||
@@ -362,7 +461,6 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 1);
|
||||
assert.equal(group.activeEditor, input1);
|
||||
assert.equal(group.isActive(input1), true);
|
||||
assert.equal(group.isPreview(input1), false);
|
||||
assert.equal(group.isPinned(input1), true);
|
||||
assert.equal(group.isPinned(0), true);
|
||||
|
||||
@@ -386,7 +484,6 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 1);
|
||||
assert.equal(group.activeEditor, input2);
|
||||
assert.equal(group.isActive(input2), true);
|
||||
assert.equal(group.isPreview(input2), true);
|
||||
assert.equal(group.isPinned(input2), false);
|
||||
assert.equal(group.isPinned(0), false);
|
||||
|
||||
@@ -416,7 +513,6 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 1);
|
||||
assert.equal(group.activeEditor, input3);
|
||||
assert.equal(group.isActive(input3), true);
|
||||
assert.equal(group.isPreview(input3), false);
|
||||
assert.equal(group.isPinned(input3), true);
|
||||
assert.equal(group.isPinned(0), true);
|
||||
|
||||
@@ -446,7 +542,6 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 1);
|
||||
assert.equal(group.activeEditor, input4);
|
||||
assert.equal(group.isActive(input4), true);
|
||||
assert.equal(group.isPreview(input4), true);
|
||||
assert.equal(group.isPinned(input4), false);
|
||||
assert.equal(group.isPinned(0), false);
|
||||
|
||||
@@ -484,13 +579,10 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.activeEditor, input3);
|
||||
assert.equal(group.isActive(input1), false);
|
||||
assert.equal(group.isPinned(input1), true);
|
||||
assert.equal(group.isPreview(input1), false);
|
||||
assert.equal(group.isActive(input2), false);
|
||||
assert.equal(group.isPinned(input2), true);
|
||||
assert.equal(group.isPreview(input2), false);
|
||||
assert.equal(group.isActive(input3), true);
|
||||
assert.equal(group.isPinned(input3), true);
|
||||
assert.equal(group.isPreview(input3), false);
|
||||
|
||||
assert.equal(events.opened[0], input1);
|
||||
assert.equal(events.opened[1], input2);
|
||||
@@ -523,7 +615,7 @@ suite('Workbench editor groups', () => {
|
||||
group.closeEditor(sameInput1);
|
||||
assert.equal(events.closed[0].editor, input1);
|
||||
|
||||
group.closeAllEditors();
|
||||
closeAllEditors(group);
|
||||
|
||||
assert.equal(events.closed.length, 3);
|
||||
assert.equal(group.count, 0);
|
||||
@@ -576,7 +668,7 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[1], input2);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[2], input1);
|
||||
|
||||
group.closeAllEditors();
|
||||
closeAllEditors(group);
|
||||
|
||||
assert.equal(events.closed.length, 3);
|
||||
assert.equal(group.count, 0);
|
||||
@@ -600,15 +692,13 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.isActive(input1), true);
|
||||
assert.equal(group.isPinned(input1), true);
|
||||
assert.equal(group.isPinned(0), true);
|
||||
assert.equal(group.isPreview(input1), false);
|
||||
assert.equal(group.isActive(input2), false);
|
||||
assert.equal(group.isPinned(input2), true);
|
||||
assert.equal(group.isPinned(1), true);
|
||||
assert.equal(group.isPreview(input2), false);
|
||||
assert.equal(group.isActive(input3), false);
|
||||
assert.equal(group.isPinned(input3), true);
|
||||
assert.equal(group.isPinned(2), true);
|
||||
assert.equal(group.isPreview(input3), false);
|
||||
assert.equal(group.isPinned(input3), true);
|
||||
|
||||
const mru = group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE);
|
||||
assert.equal(mru[0], input1);
|
||||
@@ -634,7 +724,7 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.activeEditor, input3);
|
||||
assert.equal(group.isActive(input3), true);
|
||||
assert.equal(group.isPinned(input3), false);
|
||||
assert.equal(group.isPreview(input3), true);
|
||||
assert.equal(!group.isPinned(input3), true);
|
||||
|
||||
assert.equal(events.opened[0], input1);
|
||||
assert.equal(events.opened[1], input2);
|
||||
@@ -703,7 +793,6 @@ suite('Workbench editor groups', () => {
|
||||
|
||||
assert.equal(group.activeEditor, input3);
|
||||
assert.equal(group.isPinned(input3), true);
|
||||
assert.equal(group.isPreview(input3), false);
|
||||
assert.equal(group.isActive(input3), true);
|
||||
assert.equal(events.pinned[0], input3);
|
||||
assert.equal(group.count, 3);
|
||||
@@ -712,7 +801,6 @@ suite('Workbench editor groups', () => {
|
||||
|
||||
assert.equal(group.activeEditor, input3);
|
||||
assert.equal(group.isPinned(input1), false);
|
||||
assert.equal(group.isPreview(input1), true);
|
||||
assert.equal(group.isActive(input1), false);
|
||||
assert.equal(events.unpinned[0], input1);
|
||||
assert.equal(group.count, 3);
|
||||
@@ -883,6 +971,25 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[2], input3);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[3], input4);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[4], input5);
|
||||
|
||||
assert.equal(events.moved.length, 4);
|
||||
group.moveEditor(input1, 0);
|
||||
assert.equal(events.moved.length, 4);
|
||||
group.moveEditor(input1, -1);
|
||||
assert.equal(events.moved.length, 4);
|
||||
|
||||
group.moveEditor(input5, 4);
|
||||
assert.equal(events.moved.length, 4);
|
||||
group.moveEditor(input5, 100);
|
||||
assert.equal(events.moved.length, 4);
|
||||
|
||||
group.moveEditor(input5, -1);
|
||||
assert.equal(events.moved.length, 5);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[0], input5);
|
||||
|
||||
group.moveEditor(input1, 100);
|
||||
assert.equal(events.moved.length, 6);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[4], input1);
|
||||
});
|
||||
|
||||
test('Multiple Editors - move editor across groups', function () {
|
||||
@@ -978,11 +1085,11 @@ suite('Workbench editor groups', () => {
|
||||
group.openEditor(input5, { active: true, pinned: true });
|
||||
|
||||
// Close Others
|
||||
group.closeEditors(group.activeEditor!);
|
||||
closeEditors(group, group.activeEditor!);
|
||||
assert.equal(group.activeEditor, input5);
|
||||
assert.equal(group.count, 1);
|
||||
|
||||
group.closeAllEditors();
|
||||
closeAllEditors(group);
|
||||
group.openEditor(input1, { active: true, pinned: true });
|
||||
group.openEditor(input2, { active: true, pinned: true });
|
||||
group.openEditor(input3, { active: true, pinned: true });
|
||||
@@ -992,14 +1099,14 @@ suite('Workbench editor groups', () => {
|
||||
|
||||
// Close Left
|
||||
assert.equal(group.activeEditor, input3);
|
||||
group.closeEditors(group.activeEditor!, CloseDirection.LEFT);
|
||||
closeEditors(group, group.activeEditor!, CloseDirection.LEFT);
|
||||
assert.equal(group.activeEditor, input3);
|
||||
assert.equal(group.count, 3);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[0], input3);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[1], input4);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[2], input5);
|
||||
|
||||
group.closeAllEditors();
|
||||
closeAllEditors(group);
|
||||
group.openEditor(input1, { active: true, pinned: true });
|
||||
group.openEditor(input2, { active: true, pinned: true });
|
||||
group.openEditor(input3, { active: true, pinned: true });
|
||||
@@ -1009,7 +1116,7 @@ suite('Workbench editor groups', () => {
|
||||
|
||||
// Close Right
|
||||
assert.equal(group.activeEditor, input3);
|
||||
group.closeEditors(group.activeEditor!, CloseDirection.RIGHT);
|
||||
closeEditors(group, group.activeEditor!, CloseDirection.RIGHT);
|
||||
assert.equal(group.activeEditor, input3);
|
||||
assert.equal(group.count, 3);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[0], input1);
|
||||
@@ -1053,7 +1160,7 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(openedEditor, testJs);
|
||||
assert.equal(group.previewEditor, styleCss);
|
||||
assert.equal(group.activeEditor, testJs);
|
||||
assert.equal(group.isPreview(styleCss), true);
|
||||
assert.equal(group.isPinned(styleCss), false);
|
||||
assert.equal(group.isPinned(testJs), true);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[0], styleCss);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[1], testJs);
|
||||
@@ -1064,7 +1171,7 @@ suite('Workbench editor groups', () => {
|
||||
group.openEditor(indexHtml2, { active: true });
|
||||
assert.equal(group.activeEditor, indexHtml2);
|
||||
assert.equal(group.previewEditor, indexHtml2);
|
||||
assert.equal(group.isPreview(indexHtml2), true);
|
||||
assert.equal(group.isPinned(indexHtml2), false);
|
||||
assert.equal(group.isPinned(testJs), true);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[0], testJs);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL)[1], indexHtml2);
|
||||
@@ -1081,14 +1188,12 @@ suite('Workbench editor groups', () => {
|
||||
const indexHtml3 = input('index.html');
|
||||
group.pin(indexHtml3);
|
||||
assert.equal(group.isPinned(indexHtml3), true);
|
||||
assert.equal(group.isPreview(indexHtml3), false);
|
||||
assert.equal(group.activeEditor, testJs);
|
||||
|
||||
// [test.js, index.html] -> [test.js, file.ts, index.html]
|
||||
const fileTs = input('file.ts');
|
||||
group.openEditor(fileTs, { active: true, pinned: true });
|
||||
assert.equal(group.isPinned(fileTs), true);
|
||||
assert.equal(group.isPreview(fileTs), false);
|
||||
assert.equal(group.count, 3);
|
||||
assert.equal(group.activeEditor, fileTs);
|
||||
|
||||
@@ -1096,7 +1201,6 @@ suite('Workbench editor groups', () => {
|
||||
group.unpin(fileTs);
|
||||
assert.equal(group.count, 3);
|
||||
assert.equal(group.isPinned(fileTs), false);
|
||||
assert.equal(group.isPreview(fileTs), true);
|
||||
assert.equal(group.activeEditor, fileTs);
|
||||
|
||||
// [test.js, /file.ts/, index.html] -> [test.js, /other.ts/, index.html]
|
||||
@@ -1132,7 +1236,6 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.activeEditor, testJs);
|
||||
assert.ok(group.getEditors(EditorsOrder.SEQUENTIAL)[0].matches(testJs));
|
||||
assert.equal(group.isPinned(testJs), false);
|
||||
assert.equal(group.isPreview(testJs), true);
|
||||
|
||||
// /test.js/ -> []
|
||||
group.closeEditor(testJs);
|
||||
@@ -1289,6 +1392,41 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)[1].matches(serializableInput1), true);
|
||||
});
|
||||
|
||||
test('Single group, multiple editors - persist (some not persistable, sticky editors)', function () {
|
||||
let inst = new TestInstantiationService();
|
||||
|
||||
inst.stub(IStorageService, new TestStorageService());
|
||||
inst.stub(IWorkspaceContextService, new TestContextService());
|
||||
const lifecycle = new TestLifecycleService();
|
||||
inst.stub(ILifecycleService, lifecycle);
|
||||
inst.stub(ITelemetryService, NullTelemetryService);
|
||||
|
||||
const config = new TestConfigurationService();
|
||||
config.setUserConfiguration('workbench', { editor: { openPositioning: 'right' } });
|
||||
inst.stub(IConfigurationService, config);
|
||||
|
||||
inst.invokeFunction(accessor => Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).start(accessor));
|
||||
|
||||
let group = createGroup();
|
||||
|
||||
const serializableInput1 = input();
|
||||
const nonSerializableInput2 = input('3', true);
|
||||
const serializableInput2 = input();
|
||||
|
||||
group.openEditor(serializableInput1, { active: true, pinned: true });
|
||||
group.openEditor(nonSerializableInput2, { active: true, pinned: true, sticky: true });
|
||||
group.openEditor(serializableInput2, { active: false, pinned: true });
|
||||
|
||||
assert.equal(group.count, 3);
|
||||
assert.equal(group.stickyCount, 1);
|
||||
|
||||
// Create model again - should load from storage
|
||||
group = inst.createInstance(EditorGroup, group.serialize());
|
||||
|
||||
assert.equal(group.count, 2);
|
||||
assert.equal(group.stickyCount, 0);
|
||||
});
|
||||
|
||||
test('Multiple groups, multiple editors - persist (some not persistable, causes empty group)', function () {
|
||||
let inst = new TestInstantiationService();
|
||||
|
||||
@@ -1413,7 +1551,7 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(dirty2Counter, 1);
|
||||
assert.equal(label2ChangeCounter, 1);
|
||||
|
||||
group2.closeAllEditors();
|
||||
closeAllEditors(group2);
|
||||
|
||||
(<TestEditorInput>input2).setDirty();
|
||||
(<TestEditorInput>input2).setLabel();
|
||||
@@ -1423,4 +1561,268 @@ suite('Workbench editor groups', () => {
|
||||
assert.equal(dirty1Counter, 1);
|
||||
assert.equal(label1ChangeCounter, 1);
|
||||
});
|
||||
|
||||
test('Sticky Editors', function () {
|
||||
const group = createGroup();
|
||||
|
||||
const input1 = input();
|
||||
const input2 = input();
|
||||
const input3 = input();
|
||||
const input4 = input();
|
||||
|
||||
group.openEditor(input1, { pinned: true, active: true });
|
||||
group.openEditor(input2, { pinned: true, active: true });
|
||||
group.openEditor(input3, { pinned: false, active: true });
|
||||
|
||||
assert.equal(group.stickyCount, 0);
|
||||
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL).length, 3);
|
||||
assert.equal(group.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true }).length, 3);
|
||||
assert.equal(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).length, 3);
|
||||
assert.equal(group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE, { excludeSticky: true }).length, 3);
|
||||
|
||||
// Stick last editor should move it first and pin
|
||||
group.stick(input3);
|
||||
assert.equal(group.stickyCount, 1);
|
||||
assert.equal(group.isSticky(input1), false);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
assert.equal(group.isSticky(input3), true);
|
||||
assert.equal(group.isPinned(input3), true);
|
||||
assert.equal(group.indexOf(input1), 1);
|
||||
assert.equal(group.indexOf(input2), 2);
|
||||
assert.equal(group.indexOf(input3), 0);
|
||||
|
||||
let sequentialAllEditors = group.getEditors(EditorsOrder.SEQUENTIAL);
|
||||
assert.equal(sequentialAllEditors.length, 3);
|
||||
let sequentialEditorsExcludingSticky = group.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true });
|
||||
assert.equal(sequentialEditorsExcludingSticky.length, 2);
|
||||
assert.ok(sequentialEditorsExcludingSticky.indexOf(input1) >= 0);
|
||||
assert.ok(sequentialEditorsExcludingSticky.indexOf(input2) >= 0);
|
||||
let mruAllEditors = group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE);
|
||||
assert.equal(mruAllEditors.length, 3);
|
||||
let mruEditorsExcludingSticky = group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE, { excludeSticky: true });
|
||||
assert.equal(mruEditorsExcludingSticky.length, 2);
|
||||
assert.ok(mruEditorsExcludingSticky.indexOf(input1) >= 0);
|
||||
assert.ok(mruEditorsExcludingSticky.indexOf(input2) >= 0);
|
||||
|
||||
// Sticking same editor again is a no-op
|
||||
group.stick(input3);
|
||||
assert.equal(group.isSticky(input3), true);
|
||||
|
||||
// Sticking last editor now should move it after sticky one
|
||||
group.stick(input2);
|
||||
assert.equal(group.stickyCount, 2);
|
||||
assert.equal(group.isSticky(input1), false);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), true);
|
||||
assert.equal(group.indexOf(input1), 2);
|
||||
assert.equal(group.indexOf(input2), 1);
|
||||
assert.equal(group.indexOf(input3), 0);
|
||||
|
||||
sequentialAllEditors = group.getEditors(EditorsOrder.SEQUENTIAL);
|
||||
assert.equal(sequentialAllEditors.length, 3);
|
||||
sequentialEditorsExcludingSticky = group.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true });
|
||||
assert.equal(sequentialEditorsExcludingSticky.length, 1);
|
||||
assert.ok(sequentialEditorsExcludingSticky.indexOf(input1) >= 0);
|
||||
mruAllEditors = group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE);
|
||||
assert.equal(mruAllEditors.length, 3);
|
||||
mruEditorsExcludingSticky = group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE, { excludeSticky: true });
|
||||
assert.equal(mruEditorsExcludingSticky.length, 1);
|
||||
assert.ok(mruEditorsExcludingSticky.indexOf(input1) >= 0);
|
||||
|
||||
// Sticking remaining editor also works
|
||||
group.stick(input1);
|
||||
assert.equal(group.stickyCount, 3);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), true);
|
||||
assert.equal(group.indexOf(input1), 2);
|
||||
assert.equal(group.indexOf(input2), 1);
|
||||
assert.equal(group.indexOf(input3), 0);
|
||||
|
||||
sequentialAllEditors = group.getEditors(EditorsOrder.SEQUENTIAL);
|
||||
assert.equal(sequentialAllEditors.length, 3);
|
||||
sequentialEditorsExcludingSticky = group.getEditors(EditorsOrder.SEQUENTIAL, { excludeSticky: true });
|
||||
assert.equal(sequentialEditorsExcludingSticky.length, 0);
|
||||
mruAllEditors = group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE);
|
||||
assert.equal(mruAllEditors.length, 3);
|
||||
mruEditorsExcludingSticky = group.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE, { excludeSticky: true });
|
||||
assert.equal(mruEditorsExcludingSticky.length, 0);
|
||||
|
||||
// Unsticking moves editor after sticky ones
|
||||
group.unstick(input3);
|
||||
assert.equal(group.stickyCount, 2);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 1);
|
||||
assert.equal(group.indexOf(input2), 0);
|
||||
assert.equal(group.indexOf(input3), 2);
|
||||
|
||||
// Unsticking all works
|
||||
group.unstick(input1);
|
||||
group.unstick(input2);
|
||||
assert.equal(group.stickyCount, 0);
|
||||
assert.equal(group.isSticky(input1), false);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
|
||||
group.moveEditor(input1, 0);
|
||||
group.moveEditor(input2, 1);
|
||||
group.moveEditor(input3, 2);
|
||||
|
||||
// Opening a new editor always opens after sticky editors
|
||||
group.stick(input1);
|
||||
group.stick(input2);
|
||||
group.setActive(input1);
|
||||
|
||||
const events = groupListener(group);
|
||||
|
||||
group.openEditor(input4, { pinned: true, active: true });
|
||||
assert.equal(group.indexOf(input4), 2);
|
||||
group.closeEditor(input4);
|
||||
|
||||
assert.equal(events.closed[0].sticky, false);
|
||||
|
||||
group.setActive(input2);
|
||||
|
||||
group.openEditor(input4, { pinned: true, active: true });
|
||||
assert.equal(group.indexOf(input4), 2);
|
||||
group.closeEditor(input4);
|
||||
|
||||
assert.equal(events.closed[1].sticky, false);
|
||||
|
||||
// Reset
|
||||
assert.equal(group.stickyCount, 2);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 0);
|
||||
assert.equal(group.indexOf(input2), 1);
|
||||
assert.equal(group.indexOf(input3), 2);
|
||||
|
||||
// Moving a sticky editor works
|
||||
group.moveEditor(input1, 1); // still moved within sticky range
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 1);
|
||||
assert.equal(group.indexOf(input2), 0);
|
||||
assert.equal(group.indexOf(input3), 2);
|
||||
|
||||
group.moveEditor(input1, 0); // still moved within sticky range
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 0);
|
||||
assert.equal(group.indexOf(input2), 1);
|
||||
assert.equal(group.indexOf(input3), 2);
|
||||
|
||||
group.moveEditor(input1, 2); // moved out of sticky range
|
||||
assert.equal(group.isSticky(input1), false);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 2);
|
||||
assert.equal(group.indexOf(input2), 0);
|
||||
assert.equal(group.indexOf(input3), 1);
|
||||
|
||||
group.moveEditor(input2, 2); // moved out of sticky range
|
||||
assert.equal(group.isSticky(input1), false);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 1);
|
||||
assert.equal(group.indexOf(input2), 2);
|
||||
assert.equal(group.indexOf(input3), 0);
|
||||
|
||||
// Reset
|
||||
group.moveEditor(input1, 0);
|
||||
group.moveEditor(input2, 1);
|
||||
group.moveEditor(input3, 2);
|
||||
group.stick(input1);
|
||||
group.unstick(input2);
|
||||
assert.equal(group.stickyCount, 1);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 0);
|
||||
assert.equal(group.indexOf(input2), 1);
|
||||
assert.equal(group.indexOf(input3), 2);
|
||||
|
||||
// Moving a unsticky editor in works
|
||||
group.moveEditor(input3, 1); // still moved within unsticked range
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 0);
|
||||
assert.equal(group.indexOf(input2), 2);
|
||||
assert.equal(group.indexOf(input3), 1);
|
||||
|
||||
group.moveEditor(input3, 2); // still moved within unsticked range
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.indexOf(input1), 0);
|
||||
assert.equal(group.indexOf(input2), 1);
|
||||
assert.equal(group.indexOf(input3), 2);
|
||||
|
||||
group.moveEditor(input3, 0); // moved into sticky range
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
assert.equal(group.isSticky(input3), true);
|
||||
assert.equal(group.indexOf(input1), 1);
|
||||
assert.equal(group.indexOf(input2), 2);
|
||||
assert.equal(group.indexOf(input3), 0);
|
||||
|
||||
group.moveEditor(input2, 0); // moved into sticky range
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), true);
|
||||
assert.equal(group.indexOf(input1), 2);
|
||||
assert.equal(group.indexOf(input2), 0);
|
||||
assert.equal(group.indexOf(input3), 1);
|
||||
|
||||
// Closing a sticky editor updates state properly
|
||||
group.stick(input1);
|
||||
group.stick(input2);
|
||||
group.unstick(input3);
|
||||
assert.equal(group.stickyCount, 2);
|
||||
group.closeEditor(input1);
|
||||
assert.equal(events.closed[2].sticky, true);
|
||||
assert.equal(group.stickyCount, 1);
|
||||
group.closeEditor(input2);
|
||||
assert.equal(events.closed[3].sticky, true);
|
||||
assert.equal(group.stickyCount, 0);
|
||||
|
||||
closeAllEditors(group);
|
||||
assert.equal(group.stickyCount, 0);
|
||||
|
||||
// Open sticky
|
||||
group.openEditor(input1, { sticky: true });
|
||||
assert.equal(group.stickyCount, 1);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
|
||||
group.openEditor(input2, { pinned: true, active: true });
|
||||
assert.equal(group.stickyCount, 1);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), false);
|
||||
|
||||
group.openEditor(input2, { sticky: true });
|
||||
assert.equal(group.stickyCount, 2);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
|
||||
group.openEditor(input3, { pinned: true, active: true });
|
||||
group.openEditor(input4, { pinned: false, active: true, sticky: true });
|
||||
assert.equal(group.stickyCount, 3);
|
||||
assert.equal(group.isSticky(input1), true);
|
||||
assert.equal(group.isSticky(input2), true);
|
||||
assert.equal(group.isSticky(input3), false);
|
||||
assert.equal(group.isSticky(input4), true);
|
||||
assert.equal(group.isPinned(input4), true);
|
||||
|
||||
assert.equal(group.indexOf(input1), 0);
|
||||
assert.equal(group.indexOf(input2), 1);
|
||||
assert.equal(group.indexOf(input3), 3);
|
||||
assert.equal(group.indexOf(input4), 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as resources from 'vs/base/common/resources';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, IEditorInput, IEditorPane, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorInput, EditorOptions, EditorsOrder, IFileEditorInput, IEditorInputFactoryRegistry, IEditorInputFactory, Extensions as EditorExtensions, ISaveOptions, IMoveResult, ITextEditorPane, ITextDiffEditorPane, IVisibleEditorPane } from 'vs/workbench/common/editor';
|
||||
import { IEditorInputWithOptions, IEditorIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, IEditorInput, IEditorPane, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorInput, EditorOptions, EditorsOrder, IFileEditorInput, IEditorInputFactoryRegistry, IEditorInputFactory, Extensions as EditorExtensions, ISaveOptions, IMoveResult, ITextEditorPane, ITextDiffEditorPane, IVisibleEditorPane } from 'vs/workbench/common/editor';
|
||||
import { IEditorOpeningEvent, EditorServiceImpl, IEditorGroupView, IEditorGroupsAccessor } from 'vs/workbench/browser/parts/editor/editor';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { IBackupFileService, IResolvedBackup } from 'vs/workbench/services/backup/common/backup';
|
||||
@@ -51,7 +51,7 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
|
||||
import { IDisposable, toDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation, ICloseAllEditorsOptions, ICloseEditorsFilter } from 'vs/workbench/services/editor/common/editorGroupsService';
|
||||
import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditorInputType, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, IOpenEditorOverrideEntry, ICustomEditorViewTypesHandler } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor';
|
||||
@@ -340,8 +340,6 @@ export class TestHistoryService implements IHistoryService {
|
||||
openLastEditLocation(): void { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class TestFileDialogService implements IFileDialogService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
@@ -547,6 +545,7 @@ export class TestEditorGroupView implements IEditorGroupView {
|
||||
activeEditor!: IEditorInput;
|
||||
previewEditor!: IEditorInput;
|
||||
count!: number;
|
||||
stickyCount!: number;
|
||||
disposed!: boolean;
|
||||
editors: ReadonlyArray<IEditorInput> = [];
|
||||
label!: string;
|
||||
@@ -578,14 +577,17 @@ export class TestEditorGroupView implements IEditorGroupView {
|
||||
openEditors(_editors: IEditorInputWithOptions[]): Promise<IEditorPane> { throw new Error('not implemented'); }
|
||||
isOpened(_editor: IEditorInput | IResourceEditorInput): boolean { return false; }
|
||||
isPinned(_editor: IEditorInput): boolean { return false; }
|
||||
isSticky(_editor: IEditorInput): boolean { return false; }
|
||||
isActive(_editor: IEditorInput): boolean { return false; }
|
||||
moveEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: IMoveEditorOptions): void { }
|
||||
copyEditor(_editor: IEditorInput, _target: IEditorGroup, _options?: ICopyEditorOptions): void { }
|
||||
closeEditor(_editor?: IEditorInput, options?: ICloseEditorOptions): Promise<void> { return Promise.resolve(); }
|
||||
closeEditors(_editors: IEditorInput[] | { except?: IEditorInput; direction?: CloseDirection; savedOnly?: boolean; }, options?: ICloseEditorOptions): Promise<void> { return Promise.resolve(); }
|
||||
closeAllEditors(): Promise<void> { return Promise.resolve(); }
|
||||
closeEditors(_editors: IEditorInput[] | ICloseEditorsFilter, options?: ICloseEditorOptions): Promise<void> { return Promise.resolve(); }
|
||||
closeAllEditors(options?: ICloseAllEditorsOptions): Promise<void> { return Promise.resolve(); }
|
||||
replaceEditors(_editors: IEditorReplacement[]): Promise<void> { return Promise.resolve(); }
|
||||
pinEditor(_editor?: IEditorInput): void { }
|
||||
stickEditor(editor?: IEditorInput | undefined): void { }
|
||||
unstickEditor(editor?: IEditorInput | undefined): void { }
|
||||
focus(): void { }
|
||||
invokeWithinContext<T>(fn: (accessor: ServicesAccessor) => T): T { throw new Error('not implemented'); }
|
||||
setActive(_isActive: boolean): void { }
|
||||
@@ -666,8 +668,8 @@ export class TestEditorService implements EditorServiceImpl {
|
||||
createEditorInput(_input: IResourceEditorInput | IUntitledTextResourceEditorInput | IResourceDiffEditorInput): EditorInput { throw new Error('not implemented'); }
|
||||
save(editors: IEditorIdentifier[], options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
|
||||
saveAll(options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
|
||||
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<void> { throw new Error('Method not implemented.'); }
|
||||
revertAll(options?: IRevertAllEditorsOptions): Promise<void> { throw new Error('Method not implemented.'); }
|
||||
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
|
||||
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
|
||||
}
|
||||
|
||||
export class TestFileService implements IFileService {
|
||||
@@ -1061,6 +1063,7 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
|
||||
}
|
||||
async save(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
|
||||
this.gotSaved = true;
|
||||
this.dirty = false;
|
||||
return this;
|
||||
}
|
||||
async saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise<IEditorInput | undefined> {
|
||||
@@ -1071,6 +1074,7 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
|
||||
this.gotReverted = true;
|
||||
this.gotSaved = false;
|
||||
this.gotSavedAs = false;
|
||||
this.dirty = false;
|
||||
}
|
||||
setDirty(): void { this.dirty = true; }
|
||||
isDirty(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user