3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import type * as vscode from 'vscode' ;
6
+ import * as vscode from 'vscode' ;
7
7
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters' ;
8
8
import { IEditorTabDto , IEditorTabGroupDto , IExtHostEditorTabsShape , MainContext , MainThreadEditorTabsShape , TabInputKind } from 'vs/workbench/api/common/extHost.protocol' ;
9
9
import { URI } from 'vs/base/common/uri' ;
@@ -162,6 +162,11 @@ class ExtHostEditorTabGroup {
162
162
}
163
163
if ( dto . isActive ) {
164
164
this . _activeTabId = dto . id ;
165
+ } else if ( this . _activeTabId === dto . id && ! dto . isActive ) {
166
+ // Events aren't guaranteed to be in order so if we receive a dto that matches the active tab id
167
+ // but isn't active we mark the active tab id as empty. This prevent onDidActiveTabChange frorm
168
+ // firing incorrectly
169
+ this . _activeTabId = '' ;
165
170
}
166
171
tab . acceptDtoUpdate ( dto ) ;
167
172
return tab ;
@@ -177,8 +182,9 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
177
182
readonly _serviceBrand : undefined ;
178
183
179
184
private readonly _proxy : MainThreadEditorTabsShape ;
180
- private readonly _onDidChangeTab = new Emitter < vscode . Tab [ ] > ( ) ;
181
- private readonly _onDidChangeTabGroup = new Emitter < void > ( ) ;
185
+ private readonly _onDidChangeTabs = new Emitter < vscode . Tab [ ] > ( ) ;
186
+ private readonly _onDidChangeActiveTab = new Emitter < vscode . Tab > ( ) ;
187
+ private readonly _onDidChangeTabGroups = new Emitter < vscode . TabGroup [ ] > ( ) ;
182
188
private readonly _onDidChangeActiveTabGroup = new Emitter < vscode . TabGroup > ( ) ;
183
189
184
190
// Have to use ! because this gets initialized via an RPC proxy
@@ -197,9 +203,10 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
197
203
const that = this ;
198
204
const obj : vscode . TabGroups = {
199
205
// never changes -> simple value
200
- onDidChangeTabGroup : that . _onDidChangeTabGroup . event ,
206
+ onDidChangeTabGroups : that . _onDidChangeTabGroups . event ,
201
207
onDidChangeActiveTabGroup : that . _onDidChangeActiveTabGroup . event ,
202
- onDidChangeTabs : that . _onDidChangeTab . event ,
208
+ onDidChangeTabs : that . _onDidChangeTabs . event ,
209
+ onDidChangeActiveTab : that . _onDidChangeActiveTab . event ,
203
210
// dynamic -> getters
204
211
get groups ( ) {
205
212
return Object . freeze ( that . _extHostTabGroups . map ( group => group . apiObject ) ) ;
@@ -259,7 +266,7 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
259
266
this . _activeGroupId = activeTabGroupId ;
260
267
this . _onDidChangeActiveTabGroup . fire ( this . tabGroups . activeTabGroup ) ;
261
268
}
262
- this . _onDidChangeTabGroup . fire ( ) ;
269
+ this . _onDidChangeTabGroups . fire ( this . _extHostTabGroups . map ( g => g . apiObject ) ) ;
263
270
}
264
271
265
272
$acceptTabGroupUpdate ( groupDto : IEditorTabGroupDto ) {
@@ -275,7 +282,7 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
275
282
this . _onDidChangeActiveTabGroup . fire ( group . apiObject ) ;
276
283
}
277
284
}
278
- this . _onDidChangeTabGroup . fire ( ) ;
285
+ this . _onDidChangeTabGroups . fire ( [ group . apiObject ] ) ;
279
286
}
280
287
281
288
$acceptTabUpdate ( groupId : number , tabDto : IEditorTabDto ) {
@@ -284,6 +291,9 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
284
291
throw new Error ( 'Update Tabs IPC call received before group creation.' ) ;
285
292
}
286
293
const tab = group . acceptTabDtoUpdate ( tabDto ) ;
287
- this . _onDidChangeTab . fire ( [ tab . apiObject ] ) ;
294
+ this . _onDidChangeTabs . fire ( [ tab . apiObject ] ) ;
295
+ if ( tab . apiObject . isActive ) {
296
+ this . _onDidChangeActiveTab . fire ( tab . apiObject ) ;
297
+ }
288
298
}
289
299
}
0 commit comments