From 264be51f6668ff9ce0cf4f00d6c78aeb308a329e Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 6 Jun 2023 16:24:06 -0400 Subject: [PATCH] Fixes poor experience w/ resetting view locations --- src/commands/resetViewsLayout.ts | 24 ++++++++++--- src/config.ts | 10 +++--- src/constants.ts | 62 +++++++++++++++++++++++++++++++-- src/plus/webviews/graph/registration.ts | 4 +-- src/system/command.ts | 18 +++------- src/views/viewBase.ts | 7 ++-- src/webviews/webviewController.ts | 4 +-- src/webviews/webviewsController.ts | 4 +-- 8 files changed, 100 insertions(+), 33 deletions(-) diff --git a/src/commands/resetViewsLayout.ts b/src/commands/resetViewsLayout.ts index b116827..7c22a69 100644 --- a/src/commands/resetViewsLayout.ts +++ b/src/commands/resetViewsLayout.ts @@ -1,7 +1,7 @@ -import { viewsConfigKeys } from '../config'; -import { Commands } from '../constants'; +import type { QualifiedViewIds } from '../constants'; +import { Commands, viewIdsByDefaultContainerId } from '../constants'; import type { Container } from '../container'; -import { command, executeCommand } from '../system/command'; +import { command, executeCoreCommand } from '../system/command'; import { Command } from './base'; @command() @@ -11,8 +11,22 @@ export class ResetViewsLayoutCommand extends Command { } async execute() { - for (const view of viewsConfigKeys) { - void (await executeCommand(`gitlens.views.${view}.resetViewLocation`)); + // Don't use this because it will forcibly show & expand every view + // for (const view of viewIds) { + // void (await executeCoreCommand(`gitlens.views.${view}.resetViewLocation`)); + // } + + for (const [containerId, viewIds] of viewIdsByDefaultContainerId) { + try { + void (await executeCoreCommand('vscode.moveViews', { + viewIds: viewIds.map(v => `gitlens.views.${v}`), + destinationId: containerId, + })); + } catch {} + + if (containerId.includes('gitlens')) { + void (await executeCoreCommand(`${containerId}.resetViewContainerLocation`)); + } } } } diff --git a/src/config.ts b/src/config.ts index b8dce46..e8a4fb8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -662,16 +662,18 @@ interface ViewsConfigs { export type ViewsConfigKeys = keyof ViewsConfigs; export const viewsConfigKeys: ViewsConfigKeys[] = [ + 'branches', 'commits', - 'repositories', + 'commitDetails', + 'contributors', 'fileHistory', 'lineHistory', - 'branches', 'remotes', + 'repositories', + 'searchAndCompare', 'stashes', 'tags', - 'contributors', - 'searchAndCompare', + 'workspaces', 'worktrees', ]; diff --git a/src/constants.ts b/src/constants.ts index ae61ed3..70ac26b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -316,8 +316,64 @@ export const enum Commands { } export type CustomEditorIds = 'rebase'; +export type TreeViewIds = + | 'branches' + | 'commits' + | 'contributors' + | 'fileHistory' + | 'lineHistory' + | 'remotes' + | 'repositories' + | 'searchAndCompare' + | 'stashes' + | 'tags' + | 'workspaces' + | 'worktrees'; export type WebviewIds = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus'; -export type WebviewViewIds = 'commitDetails' | 'graph' | 'graphDetails' | 'home' | 'timeline' | 'account'; +export type WebviewViewIds = 'account' | 'commitDetails' | 'graph' | 'graphDetails' | 'home' | 'timeline'; + +export type ViewIds = TreeViewIds | WebviewViewIds; +export type QualifiedViewIds = `gitlens.views.${ViewIds}`; + +export type ViewContainerIds = 'gitlens' | 'gitlensInspect' | 'gitlensPanel'; +export type QualifiedViewContainerIds = `workbench.view.extension.${ViewContainerIds}`; + +export type CoreViewContainerIds = 'scm'; +export type QualifiedCoreViewContainerIds = `workbench.view.${CoreViewContainerIds}`; + +// export const viewIds: ViewIds[] = [ +// 'account', +// 'branches', +// 'commits', +// 'commitDetails', +// 'contributors', +// 'fileHistory', +// 'graph', +// 'graphDetails', +// 'home', +// 'lineHistory', +// 'remotes', +// 'repositories', +// 'searchAndCompare', +// 'stashes', +// 'tags', +// 'timeline', +// 'workspaces', +// 'worktrees', +// ]; + +export const viewIdsByDefaultContainerId = new Map< + QualifiedViewContainerIds | QualifiedCoreViewContainerIds, + ViewIds[] +>([ + ['workbench.view.scm', ['branches', 'commits', 'remotes', 'repositories', 'stashes', 'tags', 'worktrees']], + ['workbench.view.extension.gitlensPanel', ['graph', 'graphDetails']], + [ + 'workbench.view.extension.gitlensInspect', + ['commitDetails', 'fileHistory', 'lineHistory', 'timeline', 'searchAndCompare'], + ], + ['workbench.view.extension.gitlens', ['home', 'workspaces', 'contributors', 'account']], +]); export type ContextKeys = | `${typeof extensionPrefix}:action:${string}` @@ -387,7 +443,9 @@ export type CoreCommands = | 'workbench.extensions.uninstallExtension' | 'workbench.files.action.focusFilesExplorer' | 'workbench.view.explorer' - | 'workbench.view.scm'; + | 'workbench.view.scm' + | `${QualifiedViewContainerIds | QualifiedCoreViewContainerIds}.resetViewContainerLocation` + | `${QualifiedViewIds}.${'focus' | 'removeView' | 'resetViewLocation' | 'toggleVisibility'}`; export type CoreGitCommands = | 'git.fetch' diff --git a/src/plus/webviews/graph/registration.ts b/src/plus/webviews/graph/registration.ts index a409468..d1780fd 100644 --- a/src/plus/webviews/graph/registration.ts +++ b/src/plus/webviews/graph/registration.ts @@ -73,8 +73,8 @@ export function registerGraphWebviewCommands(container: Container, webview: Webv registerCommand('gitlens.graph.switchToPanelLayout', async () => { await configuration.updateEffective('graph.layout', 'panel'); queueMicrotask(async () => { - await executeCommand('gitlens.views.graph.resetViewLocation'); - await executeCommand('gitlens.views.graphDetails.resetViewLocation'); + await executeCoreCommand('gitlens.views.graph.resetViewLocation'); + await executeCoreCommand('gitlens.views.graphDetails.resetViewLocation'); void executeCommand(Commands.ShowGraphView); }); }), diff --git a/src/system/command.ts b/src/system/command.ts index a7985f4..054ed54 100644 --- a/src/system/command.ts +++ b/src/system/command.ts @@ -42,9 +42,7 @@ export function executeActionCommand(action: Action, return commands.executeCommand(`${Commands.ActionPrefix}${action}`, { ...args, type: action }); } -type SupportedCommands = Commands | `gitlens.views.${string}.focus` | `gitlens.views.${string}.resetViewLocation`; - -export function createCommand(command: SupportedCommands, title: string, ...args: T): CoreCommand { +export function createCommand(command: Commands, title: string, ...args: T): CoreCommand { return { command: command, title: title, @@ -52,16 +50,10 @@ export function createCommand(command: SupportedCommands, t }; } -export function executeCommand(command: SupportedCommands): Thenable; -export function executeCommand(command: SupportedCommands, arg: T): Thenable; -export function executeCommand( - command: SupportedCommands, - ...args: T -): Thenable; -export function executeCommand( - command: SupportedCommands, - ...args: T -): Thenable { +export function executeCommand(command: Commands): Thenable; +export function executeCommand(command: Commands, arg: T): Thenable; +export function executeCommand(command: Commands, ...args: T): Thenable; +export function executeCommand(command: Commands, ...args: T): Thenable { return commands.executeCommand(command, ...args); } diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index b72133b..c5408ed 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -28,8 +28,9 @@ import type { WorktreesViewConfig, } from '../config'; import { viewsCommonConfigKeys, viewsConfigKeys } from '../config'; +import type { TreeViewIds } from '../constants'; import type { Container } from '../container'; -import { executeCommand } from '../system/command'; +import { executeCoreCommand } from '../system/command'; import { configuration } from '../system/configuration'; import { debug, log } from '../system/decorators/log'; import { once } from '../system/event'; @@ -137,7 +138,7 @@ export abstract class ViewBase< constructor( public readonly container: Container, - public readonly id: `gitlens.views.${ViewsConfigKeys}`, + public readonly id: `gitlens.views.${TreeViewIds}`, public readonly name: string, private readonly trackingFeature: TrackedUsageFeatures, ) { @@ -591,7 +592,7 @@ export abstract class ViewBase< const scope = getLogScope(); try { - void (await executeCommand(`${this.id}.focus`, options)); + void (await executeCoreCommand(`${this.id}.focus`, options)); } catch (ex) { Logger.error(ex, scope); } diff --git a/src/webviews/webviewController.ts b/src/webviews/webviewController.ts index 94080d7..97a1d2d 100644 --- a/src/webviews/webviewController.ts +++ b/src/webviews/webviewController.ts @@ -3,7 +3,7 @@ import { Disposable, EventEmitter, Uri, ViewColumn, window, workspace } from 'vs import { getNonce } from '@env/crypto'; import type { Commands, CustomEditorIds, WebviewIds, WebviewViewIds } from '../constants'; import type { Container } from '../container'; -import { executeCommand } from '../system/command'; +import { executeCommand, executeCoreCommand } from '../system/command'; import { setContext } from '../system/context'; import { debug, logName } from '../system/decorators/log'; import { serialize } from '../system/decorators/serialize'; @@ -269,7 +269,7 @@ export class WebviewController< ); } } else if (this.isView()) { - await executeCommand(`${this.id}.focus`, options); + await executeCoreCommand(`${this.id}.focus`, options); if (loading) { this.provider.onVisibilityChanged?.(true); } diff --git a/src/webviews/webviewsController.ts b/src/webviews/webviewsController.ts index 10e5a8f..793a650 100644 --- a/src/webviews/webviewsController.ts +++ b/src/webviews/webviewsController.ts @@ -10,7 +10,7 @@ import { Disposable, Uri, ViewColumn, window } from 'vscode'; import type { Commands, WebviewIds, WebviewViewIds } from '../constants'; import type { Container } from '../container'; import { ensurePlusFeaturesEnabled } from '../plus/subscription/utils'; -import { executeCommand, registerCommand } from '../system/command'; +import { executeCoreCommand, registerCommand } from '../system/command'; import { debug } from '../system/decorators/log'; import { Logger } from '../system/logger'; import { getLogScope } from '../system/logger.scope'; @@ -191,7 +191,7 @@ export class WebviewsController implements Disposable { Logger.debug(scope, `Showing webview view (${descriptor.id})`); registration.pendingShowArgs = [options, ...args]; - return void executeCommand(`${descriptor.id}.focus`, options); + return void executeCoreCommand(`${descriptor.id}.focus`, options); }, } satisfies WebviewViewProxy; }