Skip to content

Commit ccf72bb

Browse files
committed
Improves view revealing
1 parent 6fab27b commit ccf72bb

File tree

11 files changed

+171
-91
lines changed

11 files changed

+171
-91
lines changed

src/commands/git/remote.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,13 @@ export class RemoteGitCommand extends QuickCommand<State> {
326326

327327
endSteps(state);
328328

329-
await state.repo.addRemote(state.name, state.url, state.flags.includes('-f') ? { fetch: true } : undefined);
329+
const remote = await state.repo.addRemote(
330+
state.name,
331+
state.url,
332+
state.flags.includes('-f') ? { fetch: true } : undefined,
333+
);
330334
if (state.reveal !== false) {
331-
void reveal(undefined, {
335+
void reveal(remote, {
332336
focus: true,
333337
select: true,
334338
});

src/git/actions/branch.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,13 @@ export function rename(repo?: string | Repository, ref?: GitBranchReference, nam
3838
});
3939
}
4040

41-
export async function reveal(
41+
export function reveal(
4242
branch: GitBranchReference,
4343
options?: {
4444
select?: boolean;
4545
focus?: boolean;
4646
expand?: boolean | number;
4747
},
4848
) {
49-
const view = branch.remote ? Container.instance.views.remotes : Container.instance.views.branches;
50-
const node = view.canReveal
51-
? await view.revealBranch(branch, options)
52-
: await Container.instance.views.repositories.revealBranch(branch, options);
53-
54-
if (node == null) {
55-
void view.show({ preserveFocus: !options?.focus });
56-
}
57-
return node;
49+
return Container.instance.views.revealBranch(branch, options);
5850
}

src/git/actions/commit.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -770,31 +770,15 @@ export async function restoreFile(file: string | GitFile, revision: GitRevisionR
770770
await Container.instance.git.checkout(revision.repoPath, ref, { path: path });
771771
}
772772

773-
export async function reveal(
773+
export function reveal(
774774
commit: GitRevisionReference,
775775
options?: {
776776
select?: boolean;
777777
focus?: boolean;
778778
expand?: boolean | number;
779779
},
780780
) {
781-
const views = [
782-
Container.instance.views.commits,
783-
Container.instance.views.branches,
784-
Container.instance.views.remotes,
785-
];
786-
787-
// TODO@eamodio stop duplicate notifications
788-
789-
for (const view of views) {
790-
const node = view.canReveal
791-
? await view.revealCommit(commit, options)
792-
: await Container.instance.views.repositories.revealCommit(commit, options);
793-
if (node != null) return node;
794-
}
795-
796-
void views[0].show({ preserveFocus: !options?.focus });
797-
return undefined;
781+
return Container.instance.views.revealCommit(commit, options);
798782
}
799783

800784
export async function showDetailsQuickPick(commit: GitCommit, uri?: Uri): Promise<void>;

src/git/actions/contributor.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,13 @@ export function addAuthors(repo?: string | Repository, contributors?: GitContrib
1010
});
1111
}
1212

13-
export async function reveal(
13+
export function reveal(
1414
contributor: GitContributor,
1515
options?: {
1616
select?: boolean;
1717
focus?: boolean;
1818
expand?: boolean | number;
1919
},
2020
) {
21-
const view = Container.instance.views.contributors;
22-
const node = view.canReveal
23-
? await view.revealContributor(contributor, options)
24-
: await Container.instance.views.repositories.revealContributor(contributor, options);
25-
if (node == null) {
26-
void view.show({ preserveFocus: !options?.focus });
27-
}
28-
return node;
21+
return Container.instance.views.revealContributor(contributor, options);
2922
}

src/git/actions/remote.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,13 @@ export async function remove(repo: string | Repository, remote: string) {
4848
});
4949
}
5050

51-
export async function reveal(
51+
export function reveal(
5252
remote: GitRemote | undefined,
5353
options?: {
5454
select?: boolean;
5555
focus?: boolean;
5656
expand?: boolean | number;
5757
},
5858
) {
59-
const view = Container.instance.views.remotes;
60-
const node =
61-
remote != null
62-
? view.canReveal
63-
? await view.revealRemote(remote, options)
64-
: await Container.instance.views.repositories.revealRemote(remote, options)
65-
: undefined;
66-
if (node == null) {
67-
void view.show({ preserveFocus: !options?.focus });
68-
}
69-
return node;
59+
return Container.instance.views.revealRemote(remote, options);
7060
}

src/git/actions/repository.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function switchTo(repos?: string | string[] | Repository | Repository[],
6565
});
6666
}
6767

68-
export async function reveal(
68+
export function reveal(
6969
repoPath: string,
7070
view?: ViewsWithRepositoryFolders,
7171
options?: {
@@ -74,11 +74,5 @@ export async function reveal(
7474
expand?: boolean | number;
7575
},
7676
) {
77-
const node = view?.canReveal
78-
? await view.revealRepository(repoPath, options)
79-
: await Container.instance.views.repositories.revealRepository(repoPath, options);
80-
if (node == null) {
81-
void (view ?? Container.instance.views.repositories).show({ preserveFocus: !options?.focus });
82-
}
83-
return node;
77+
return Container.instance.views.revealRepository(repoPath, view, options);
8478
}

src/git/actions/stash.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,15 @@ export function push(
6060
});
6161
}
6262

63-
export async function reveal(
63+
export function reveal(
6464
stash: GitStashReference,
6565
options?: {
6666
select?: boolean;
6767
focus?: boolean;
6868
expand?: boolean | number;
6969
},
7070
) {
71-
const view = Container.instance.views.stashes;
72-
const node = view.canReveal
73-
? await view.revealStash(stash, options)
74-
: await Container.instance.views.repositories.revealStash(stash, options);
75-
if (node == null) {
76-
void view.show({ preserveFocus: !options?.focus });
77-
}
78-
return node;
71+
return Container.instance.views.revealStash(stash, options);
7972
}
8073

8174
export function showDetailsView(

src/git/actions/tag.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,13 @@ export function remove(repo?: string | Repository, refs?: GitTagReference | GitT
2626
});
2727
}
2828

29-
export async function reveal(
29+
export function reveal(
3030
tag: GitTagReference,
3131
options?: {
3232
select?: boolean;
3333
focus?: boolean;
3434
expand?: boolean | number;
3535
},
3636
) {
37-
const view = Container.instance.views.tags;
38-
const node = view.canReveal
39-
? await view.revealTag(tag, options)
40-
: await Container.instance.views.repositories.revealTag(tag, options);
41-
if (node == null) {
42-
void view.show({ preserveFocus: !options?.focus });
43-
}
44-
return node;
37+
return Container.instance.views.revealTag(tag, options);
4538
}

src/git/actions/worktree.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,11 @@ export function remove(repo?: string | Repository, uris?: Uri[]) {
7676
});
7777
}
7878

79-
export async function reveal(
80-
worktree: GitWorktree | undefined,
79+
export function reveal(
80+
worktree: GitWorktree,
8181
options?: { select?: boolean; focus?: boolean; expand?: boolean | number },
8282
) {
83-
const view = Container.instance.views.worktrees;
84-
const node =
85-
worktree != null
86-
? view.canReveal
87-
? await view.revealWorktree(worktree, options)
88-
: await Container.instance.views.repositories.revealWorktree(worktree, options)
89-
: undefined;
90-
if (node == null) {
91-
void view.show({ preserveFocus: !options?.focus });
92-
}
93-
return node;
83+
return Container.instance.views.revealWorktree(worktree, options);
9484
}
9585

9686
type OpenFlags = Extract<

src/views/viewBase.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,16 @@ export abstract class ViewBase<
720720
const scope = getLogScope();
721721

722722
try {
723-
void (await executeCoreCommand(`${this.id}.focus`, options));
723+
const command = `${this.id}.focus` as const;
724+
// If we haven't been initialized, the focus command will show the view, but won't focus it, so wait until it's initialized and then focus again
725+
if (!this.initialized) {
726+
void executeCoreCommand(command, options);
727+
await new Promise<void>(resolve => {
728+
void once(this._onDidInitialize.event)(() => resolve(), this);
729+
});
730+
}
731+
732+
void (await executeCoreCommand(command, options));
724733
} catch (ex) {
725734
Logger.error(ex, scope);
726735
}

0 commit comments

Comments
 (0)