From 2d73fccfe3017355ba744e23b3b94be079fbb829 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 12 Dec 2020 02:45:28 -0500 Subject: [PATCH] Expands only the active or starred repos Commits view will also expand repos with changes --- src/git/gitService.ts | 16 ++++++++++++++++ src/views/commitsView.ts | 13 +++++++++---- src/views/nodes/viewNode.ts | 10 ++++++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 6129953..13a0ee0 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -3427,6 +3427,22 @@ export class GitService implements Disposable { return repository.hasTrackingBranch(); } + @log({ + args: { + 1: (editor: TextEditor) => + editor != null ? `TextEditor(${Logger.toLoggable(editor.document.uri)})` : 'undefined', + }, + }) + async isActiveRepoPath(repoPath: string | undefined, editor?: TextEditor): Promise { + if (repoPath == null) return false; + + editor = editor ?? window.activeTextEditor; + if (editor == null) return false; + + const doc = await Container.tracker.getOrAdd(editor.document.uri); + return repoPath === doc?.uri.repoPath; + } + isTrackable(scheme: string): boolean; isTrackable(uri: Uri): boolean; isTrackable(schemeOruri: string | Uri): boolean { diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index 7fcdb7f..46d267d 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -67,13 +67,18 @@ export class CommitsRepositoryNode extends RepositoryFolderNode { this.splatted = false; - const branch = await this.repo.getBranch(); + let expand = this.repo.starred; + const [active, branch] = await Promise.all([ + expand ? undefined : Container.git.isActiveRepoPath(this.uri.repoPath), + this.repo.getBranch(), + ]); + if (!expand && (active || (branch?.state.ahead ?? 0) > 0 || (branch?.state.behind ?? 0) > 0)) { + expand = true; + } const item = new TreeItem( this.repo.formattedName ?? this.uri.repoPath ?? '', - (branch?.state.ahead ?? 0) > 0 || (branch?.state.behind ?? 0) > 0 - ? TreeItemCollapsibleState.Expanded - : TreeItemCollapsibleState.Collapsed, + expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed, ); item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`; diff --git a/src/views/nodes/viewNode.ts b/src/views/nodes/viewNode.ts index aaa76a4..3195482 100644 --- a/src/views/nodes/viewNode.ts +++ b/src/views/nodes/viewNode.ts @@ -1,5 +1,6 @@ 'use strict'; import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeViewVisibilityChangeEvent } from 'vscode'; +import { Container } from '../../container'; import { GitFile, GitReference, @@ -322,12 +323,17 @@ export abstract class RepositoryFolderNode< return RepositoryFolderNode.getId(this.repo.path); } - getTreeItem(): TreeItem | Promise { + async getTreeItem(): Promise { this.splatted = false; + let expand = this.repo.starred; + if (!expand) { + expand = await Container.git.isActiveRepoPath(this.uri.repoPath); + } + const item = new TreeItem( this.repo.formattedName ?? this.uri.repoPath ?? '', - TreeItemCollapsibleState.Expanded, + expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed, ); item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`; item.tooltip = `${