@@ -224,8 +224,9 @@ export class SCMActiveRepositoryContextKeyController implements IWorkbenchContri
224224 private activeRepositoryNameContextKey : IContextKey < string > ;
225225 private activeRepositoryBranchNameContextKey : IContextKey < string > ;
226226
227+ private focusedRepository : ISCMRepository | undefined = undefined ;
228+ private focusDisposable : IDisposable = Disposable . None ;
227229 private readonly disposables = new DisposableStore ( ) ;
228- private readonly focusedRepositoryDisposables = new DisposableStore ( ) ;
229230
230231 constructor (
231232 @IContextKeyService contextKeyService : IContextKeyService ,
@@ -254,28 +255,25 @@ export class SCMActiveRepositoryContextKeyController implements IWorkbenchContri
254255 return ;
255256 }
256257
257- const activeResourceRepository = Iterable . find (
258- this . scmViewService . visibleRepositories ,
258+ const repository = Iterable . find (
259+ this . scmViewService . repositories ,
259260 r => Boolean ( r . provider . rootUri && this . uriIdentityService . extUri . isEqualOrParent ( activeResource , r . provider . rootUri ) )
260261 ) ;
261262
262- this . onDidFocusRepository ( activeResourceRepository ) ;
263+ this . onDidFocusRepository ( repository ) ;
263264 }
264265
265266 private onDidFocusRepository ( repository : ISCMRepository | undefined ) : void {
266- this . focusedRepositoryDisposables . clear ( ) ;
267-
268- if ( ! repository ) {
267+ if ( ! repository || this . focusedRepository === repository ) {
269268 return ;
270269 }
271270
272- this . focusedRepositoryDisposables . add ( repository . provider . onDidChangeHistoryProvider ( ( ) => {
273- if ( repository . provider . historyProvider ) {
274- this . focusedRepositoryDisposables . add ( repository . provider . historyProvider . onDidChangeCurrentHistoryItemGroup ( ( ) => this . updateContextKeys ( repository ) ) ) ;
275- }
271+ this . focusDisposable . dispose ( ) ;
272+ this . focusedRepository = repository ;
276273
277- this . updateContextKeys ( repository ) ;
278- } ) ) ;
274+ if ( repository && repository . provider . onDidChangeStatusBarCommands ) {
275+ this . focusDisposable = repository . provider . onDidChangeStatusBarCommands ( ( ) => this . updateContextKeys ( repository ) ) ;
276+ }
279277
280278 this . updateContextKeys ( repository ) ;
281279 }
@@ -284,6 +282,11 @@ export class SCMActiveRepositoryContextKeyController implements IWorkbenchContri
284282 this . activeRepositoryNameContextKey . set ( repository ?. provider . name ?? '' ) ;
285283 this . activeRepositoryBranchNameContextKey . set ( repository ?. provider . historyProvider ?. currentHistoryItemGroup ?. label ?? '' ) ;
286284 }
285+
286+ dispose ( ) : void {
287+ this . focusDisposable . dispose ( ) ;
288+ this . disposables . dispose ( ) ;
289+ }
287290}
288291
289292export class SCMActiveResourceContextKeyController implements IWorkbenchContribution {
0 commit comments