Skip to content

Commit 69ccbee

Browse files
committed
Avoids extra Visual History tabs
1 parent 1672cc9 commit 69ccbee

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/webviews/plus/timeline/timelineWebview.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
import type { TimelineWebviewShowingArgs } from './registration';
8383
import {
8484
areTimelineScopesEqual,
85+
areTimelineScopesEquivalent,
8586
deserializeTimelineScope,
8687
isTimelineScope,
8788
serializeTimelineScope,
@@ -155,7 +156,7 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
155156
}
156157
}
157158

158-
return areTimelineScopesEqual(scope, this._context.scope);
159+
return areTimelineScopesEquivalent(scope, this._context.scope);
159160
}
160161

161162
getSplitArgs(): WebviewShowingArgs<TimelineWebviewShowingArgs, State> {
@@ -210,9 +211,8 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
210211
}
211212
}
212213

213-
await this.updateScope(scope, true);
214-
215-
if (!loading) {
214+
const changed = await this.updateScope(scope, true, true);
215+
if (!loading && (changed || !this.host.visible)) {
216216
this.updateState();
217217
}
218218

@@ -903,7 +903,11 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
903903

904904
private _repositorySubscription: SubscriptionManager<Repository> | undefined;
905905

906-
private async updateScope(scope: TimelineScope | undefined, silent?: boolean): Promise<boolean> {
906+
private async updateScope(
907+
scope: TimelineScope | undefined,
908+
silent?: boolean,
909+
allowEquivalent?: boolean,
910+
): Promise<boolean> {
907911
if (this._tabCloseDebounceTimer != null) {
908912
clearTimeout(this._tabCloseDebounceTimer);
909913
this._tabCloseDebounceTimer = undefined;
@@ -932,6 +936,7 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
932936
if (repo != null) {
933937
if (areUrisEqual(scope.uri, repo.uri)) {
934938
scope.type = 'repo';
939+
scope.head ??= getReference(await repo.git.branches().getBranch());
935940
}
936941

937942
this._repositorySubscription ??= new SubscriptionManager(repo, r => this.subscribeToRepository(r));
@@ -968,7 +973,12 @@ export class TimelineWebviewProvider implements WebviewProvider<State, State, Ti
968973
this._repositorySubscription?.start();
969974
}
970975

971-
if (areTimelineScopesEqual(scope, this._context.scope) && areEtagsEqual(this._context.etags, etags)) {
976+
if (
977+
areEtagsEqual(this._context.etags, etags) &&
978+
(allowEquivalent
979+
? areTimelineScopesEquivalent(scope, this._context.scope)
980+
: areTimelineScopesEqual(scope, this._context.scope))
981+
) {
972982
return false;
973983
}
974984

src/webviews/plus/timeline/utils/-webview/timeline.utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ export function areTimelineScopesEqual(
1616
);
1717
}
1818

19+
/** Check if two timeline scopes are equivalent -- allows the incoming to not specify head/base */
20+
export function areTimelineScopesEquivalent(
21+
incoming: TimelineScope | TimelineScopeSerialized | undefined,
22+
current: TimelineScope | TimelineScopeSerialized | undefined,
23+
): boolean {
24+
if (incoming === current || (incoming == null && current == null)) return true;
25+
if (incoming == null || current == null) return false;
26+
if (incoming.type !== current.type || incoming.uri.toString() !== current.uri.toString()) {
27+
return false;
28+
}
29+
30+
return (
31+
incoming.type === current.type &&
32+
incoming.uri.toString() === current.uri.toString() &&
33+
(incoming.head == null || incoming.head?.ref === current.head?.ref) &&
34+
(incoming.base == null || incoming.base?.ref === current.base?.ref)
35+
);
36+
}
37+
1938
export function isTimelineScope(o: unknown): o is TimelineScope {
2039
return o != null && typeof o === 'object' && 'type' in o && 'uri' in o;
2140
}

0 commit comments

Comments
 (0)