Skip to content

Commit 99ed434

Browse files
committed
Fixes #4426 showing hidden views
Adapts view focus command for VS Code 1.100+ - Uses a version-aware helper to use 'open' instead of 'focus' - Ensures views are shown before attempting to restore selections - Avoids hanging promise when trying to clear a hidden view
1 parent 58175d7 commit 99ed434

File tree

8 files changed

+33
-12
lines changed

8 files changed

+33
-12
lines changed

src/constants.commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export type CoreCommands =
184184
| 'workbench.view.extension.gitlensInspect'
185185
| 'workbench.view.scm'
186186
| `${ViewContainerIds | CoreViewContainerIds}.resetViewContainerLocation`
187-
| `${ViewIds}.${'focus' | 'removeView' | 'resetViewLocation' | 'toggleVisibility'}`;
187+
| `${ViewIds}.${'focus' | 'open' | 'removeView' | 'resetViewLocation' | 'toggleVisibility'}`;
188188

189189
export type CoreGitCommands =
190190
| 'git.fetch'

src/system/-webview/vscode/views.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { version as codeVersion } from 'vscode';
2+
import type { CoreCommands } from '../../../constants.commands';
3+
import type { ViewIds } from '../../../constants.views';
4+
import { compare } from '../../version';
5+
6+
export function getViewFocusCommand(viewId: ViewIds): CoreCommands {
7+
if (compare(codeVersion, '1.100') >= 0) {
8+
return `${viewId}.open`;
9+
}
10+
return `${viewId}.focus`;
11+
}

src/views/scmGroupedView.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ export class ScmGroupedView implements Disposable {
8181
// Force a "refresh" of the tree to blank it out
8282
this._cleared?.cancel();
8383
this._cleared = defer<void>();
84-
this._onDidChangeTreeData?.fire(undefined);
85-
await this._cleared.promise.catch(() => {}).finally(() => (this._cleared = undefined));
84+
if (this._tree?.visible) {
85+
this._onDidChangeTreeData?.fire(undefined);
86+
await this._cleared.promise.catch(() => {}).finally(() => (this._cleared = undefined));
87+
}
8688
this._cleared = undefined;
8789
}
8890
}

src/views/viewBase.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type { TreeViewIds, TreeViewTypes, WebviewViewTypes } from '../constants.
3939
import type { Container } from '../container';
4040
import { executeCoreCommand } from '../system/-webview/command';
4141
import { configuration } from '../system/-webview/configuration';
42+
import { getViewFocusCommand } from '../system/-webview/vscode/views';
4243
import { debug, log } from '../system/decorators/log';
4344
import { once } from '../system/event';
4445
import { debounce } from '../system/function/debounce';
@@ -911,7 +912,7 @@ export abstract class ViewBase<
911912
const scope = getLogScope();
912913

913914
try {
914-
const command = `${this.grouped ? 'gitlens.views.scm.grouped' : this.id}.focus` as const;
915+
const command = getViewFocusCommand(this.grouped ? 'gitlens.views.scm.grouped' : this.id);
915916
// 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
916917
if (this.initialized.pending) {
917918
void executeCoreCommand(command, options);

src/views/views.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { GitWorktree } from '../git/models/worktree';
1414
import { executeCommand, executeCoreCommand, registerCommand } from '../system/-webview/command';
1515
import { configuration } from '../system/-webview/configuration';
1616
import { getContext, setContext } from '../system/-webview/context';
17+
import { getViewFocusCommand } from '../system/-webview/vscode/views';
1718
import { once } from '../system/function';
1819
import { first } from '../system/iterable';
1920
import { compare } from '../system/version';
@@ -139,9 +140,9 @@ export class Views implements Disposable {
139140
const disposable = once(container.onReady)(() => {
140141
disposable?.dispose();
141142
setTimeout(() => {
142-
executeCoreCommand(`gitlens.views.scm.grouped.focus`, { preserveFocus: true });
143+
executeCoreCommand(getViewFocusCommand('gitlens.views.scm.grouped'), { preserveFocus: true });
143144
if (newInstall) {
144-
executeCoreCommand(`gitlens.views.home.focus`, { preserveFocus: true });
145+
executeCoreCommand(getViewFocusCommand('gitlens.views.home'), { preserveFocus: true });
145146
}
146147
}, 0);
147148
});
@@ -531,6 +532,10 @@ export class Views implements Disposable {
531532

532533
// Restore the last selection for this view type (if any)
533534
if (view) {
535+
if (!view.visible) {
536+
await view.show({ preserveFocus: !focus });
537+
}
538+
534539
const selection = this._lastSelectedByView.get(type);
535540
if (selection != null) {
536541
setTimeout(async () => {
@@ -549,7 +554,7 @@ export class Views implements Disposable {
549554
this.lastSelectedScmGroupedView = type;
550555

551556
if (focus) {
552-
void executeCoreCommand(`gitlens.views.scm.grouped.focus`);
557+
void executeCoreCommand(getViewFocusCommand('gitlens.views.scm.grouped'), { preserveFocus: false });
553558
}
554559

555560
return undefined;
@@ -597,7 +602,7 @@ export class Views implements Disposable {
597602
await updateScmGroupedViewsInConfig(this._scmGroupedViews);
598603

599604
// Show the view after the configuration change has been applied
600-
setTimeout(() => executeCoreCommand(`gitlens.views.${grouped ? 'scm.grouped' : type}.focus`), 1);
605+
setTimeout(() => executeCoreCommand(getViewFocusCommand(`gitlens.views.${grouped ? 'scm.grouped' : type}`), 1));
601606
}
602607

603608
private toggleScmViewVisibility(type: GroupableTreeViewTypes, visible: boolean) {
@@ -988,7 +993,7 @@ export class Views implements Disposable {
988993
case 'workspaces':
989994
return this.workspaces.show();
990995
case 'scm.grouped':
991-
return void executeCoreCommand(`gitlens.views.scm.grouped.focus`);
996+
return void executeCoreCommand(getViewFocusCommand('gitlens.views.scm.grouped'));
992997
}
993998
}
994999
}

src/webviews/apps/plus/graph/graph-header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
760760
</gl-tooltip>
761761
<gl-tooltip placement="bottom">
762762
<a
763-
href=${'command:gitlens.views.home.focus'}
763+
href=${'command:gitlens.showHomeView'}
764764
class="action-button"
765765
aria-label=${`Open GitLens Home View`}
766766
>

src/webviews/webviewController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { isCancellationError } from '../errors';
99
import { getSubscriptionNextPaidPlanId } from '../plus/gk/utils/subscription.utils';
1010
import { executeCommand, executeCoreCommand } from '../system/-webview/command';
1111
import { setContext } from '../system/-webview/context';
12+
import { getViewFocusCommand } from '../system/-webview/vscode/views';
1213
import { getScopedCounter } from '../system/counter';
1314
import { debug, logName } from '../system/decorators/log';
1415
import { sequentialize } from '../system/decorators/serialize';
@@ -382,7 +383,7 @@ export class WebviewController<
382383
);
383384
}
384385
} else if (this.is('view')) {
385-
await executeCoreCommand(`${this.id}.focus`, options);
386+
await executeCoreCommand(getViewFocusCommand(this.id), options);
386387
if (loading) {
387388
this.provider.onVisibilityChanged?.(true);
388389
}

src/webviews/webviewsController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { WebviewIds, WebviewTypes, WebviewViewIds, WebviewViewTypes } from
1414
import type { Container } from '../container';
1515
import { ensurePlusFeaturesEnabled } from '../plus/gk/utils/-webview/plus.utils';
1616
import { executeCoreCommand, registerCommand } from '../system/-webview/command';
17+
import { getViewFocusCommand } from '../system/-webview/vscode/views';
1718
import { debug } from '../system/decorators/log';
1819
import { find, first, map } from '../system/iterable';
1920
import { Logger } from '../system/logger';
@@ -255,7 +256,7 @@ export class WebviewsController implements Disposable {
255256
await onBeforeShow?.(...args);
256257
}
257258

258-
return void executeCoreCommand(`${descriptor.id}.focus`, options);
259+
return void executeCoreCommand(getViewFocusCommand(descriptor.id), options);
259260
},
260261
} satisfies WebviewViewProxy<ID, ShowingArgs, SerializedState>;
261262
}

0 commit comments

Comments
 (0)