mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
Add onDidChangeActiveTab
This commit is contained in:
@@ -109,7 +109,7 @@ suite('ExtHostEditorTabs', function () {
|
||||
);
|
||||
|
||||
let count = 0;
|
||||
extHostEditorTabs.tabGroups.onDidChangeTabGroup(() => count++);
|
||||
extHostEditorTabs.tabGroups.onDidChangeTabGroups(() => count++);
|
||||
|
||||
assert.strictEqual(count, 0);
|
||||
|
||||
@@ -339,7 +339,7 @@ suite('ExtHostEditorTabs', function () {
|
||||
});
|
||||
assert.throws(() => {
|
||||
// @ts-expect-error write to readonly prop
|
||||
extHostEditorTabs.tabGroups.onDidChangeTabGroup = undefined;
|
||||
extHostEditorTabs.tabGroups.onDidChangeTabGroups = undefined;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -493,4 +493,72 @@ suite('ExtHostEditorTabs', function () {
|
||||
assert.strictEqual(extHostEditorTabs.tabGroups.groups.map(g => g.tabs).flat().length, 0);
|
||||
assert.strictEqual(extHostEditorTabs.tabGroups.activeTabGroup?.activeTab, undefined);
|
||||
});
|
||||
|
||||
test('Active tab change event', function () {
|
||||
|
||||
const extHostEditorTabs = new ExtHostEditorTabs(
|
||||
SingleProxyRPCProtocol(new class extends mock<MainThreadEditorTabsShape>() {
|
||||
// override/implement $moveTab or $closeTab
|
||||
})
|
||||
);
|
||||
|
||||
let activeTabChangeCount = 0;
|
||||
extHostEditorTabs.tabGroups.onDidChangeActiveTab((activeTab) => {
|
||||
if (activeTab.isActive === false) {
|
||||
throw new Error('Active tab changed fired on inactive tab');
|
||||
}
|
||||
activeTabChangeCount++;
|
||||
});
|
||||
|
||||
const tab1: IEditorTabDto = createTabDto({
|
||||
id: 'uniquestring',
|
||||
isActive: true,
|
||||
label: 'label1',
|
||||
});
|
||||
|
||||
const tab2: IEditorTabDto = createTabDto({
|
||||
isActive: false,
|
||||
id: 'uniquestring2',
|
||||
label: 'label2',
|
||||
});
|
||||
|
||||
const tab3: IEditorTabDto = createTabDto({
|
||||
isActive: false,
|
||||
id: 'uniquestring3',
|
||||
label: 'label3',
|
||||
});
|
||||
|
||||
extHostEditorTabs.$acceptEditorTabModel([{
|
||||
isActive: true,
|
||||
viewColumn: 0,
|
||||
groupId: 12,
|
||||
tabs: [tab1, tab2, tab3]
|
||||
}]);
|
||||
|
||||
// Accepting a model doesn't fire an active tab change event
|
||||
assert.strictEqual(activeTabChangeCount, 0);
|
||||
|
||||
// Switching active tab works
|
||||
tab1.isActive = false;
|
||||
tab2.isActive = true;
|
||||
extHostEditorTabs.$acceptTabUpdate(12, tab1);
|
||||
extHostEditorTabs.$acceptTabUpdate(12, tab2);
|
||||
// The active tab changed so it is fired once
|
||||
assert.strictEqual(activeTabChangeCount, 1);
|
||||
|
||||
//Closing tabs out works
|
||||
tab3.isActive = true;
|
||||
extHostEditorTabs.$acceptEditorTabModel([{
|
||||
isActive: true,
|
||||
viewColumn: 0,
|
||||
groupId: 12,
|
||||
tabs: [tab3]
|
||||
}]);
|
||||
// Accepting a model doesn't fire an active tab change event
|
||||
assert.strictEqual(activeTabChangeCount, 1);
|
||||
tab3.label = 'Foobar';
|
||||
extHostEditorTabs.$acceptTabUpdate(12, tab3);
|
||||
// Something related to the active tab changed
|
||||
assert.strictEqual(activeTabChangeCount, 2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user