diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 451ff28afca..e8a696735fc 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -290,7 +290,7 @@ export class CommandCenter { } @command('git.openResource') - async openResource(resource: Resource): Promise { + async openResource(resource: Resource, preserveFocus: boolean): Promise { const repository = this.model.getRepository(resource.resourceUri); if (!repository) { @@ -301,7 +301,7 @@ export class CommandCenter { const openDiffOnClick = config.get('openDiffOnClick'); if (openDiffOnClick) { - await this._openResource(resource, undefined, true, false); + await this._openResource(resource, undefined, preserveFocus, false); } else { await this.openFile(resource); } diff --git a/src/vs/workbench/api/browser/mainThreadSCM.ts b/src/vs/workbench/api/browser/mainThreadSCM.ts index e75ac0b4da3..158de62f0c9 100644 --- a/src/vs/workbench/api/browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/browser/mainThreadSCM.ts @@ -71,8 +71,8 @@ class MainThreadSCMResource implements ISCMResource { public decorations: ISCMResourceDecorations ) { } - open(): Promise { - return this.proxy.$executeResourceCommand(this.sourceControlHandle, this.groupHandle, this.handle); + open(preserveFocus: boolean): Promise { + return this.proxy.$executeResourceCommand(this.sourceControlHandle, this.groupHandle, this.handle, preserveFocus); } toJSON(): any { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index aebcb32ae91..44d8ca55244 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1388,7 +1388,7 @@ export interface ExtHostTerminalServiceShape { export interface ExtHostSCMShape { $provideOriginalResource(sourceControlHandle: number, uri: UriComponents, token: CancellationToken): Promise; $onInputBoxValueChange(sourceControlHandle: number, value: string): void; - $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): Promise; + $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number, preserveFocus: boolean): Promise; $validateInput(sourceControlHandle: number, value: string, cursorPosition: number): Promise<[string, number] | undefined>; $setSelectedSourceControls(selectedSourceControlHandles: number[]): Promise; } diff --git a/src/vs/workbench/api/common/extHostSCM.ts b/src/vs/workbench/api/common/extHostSCM.ts index 34a3138ad32..fb3f7725d3a 100644 --- a/src/vs/workbench/api/common/extHostSCM.ts +++ b/src/vs/workbench/api/common/extHostSCM.ts @@ -266,14 +266,14 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG return this._resourceStatesMap.get(handle); } - $executeResourceCommand(handle: number): Promise { + $executeResourceCommand(handle: number, preserveFocus: boolean): Promise { const command = this._resourceStatesCommandsMap.get(handle); if (!command) { return Promise.resolve(undefined); } - return asPromise(() => this._commands.executeCommand(command.command, ...(command.arguments || []))); + return asPromise(() => this._commands.executeCommand(command.command, ...(command.arguments || []), preserveFocus)); } _takeResourceStateSnapshot(): SCMRawResourceSplice[] { @@ -628,7 +628,7 @@ export class ExtHostSCM implements ExtHostSCMShape { return Promise.resolve(undefined); } - $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): Promise { + $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number, preserveFocus: boolean): Promise { this.logService.trace('ExtHostSCM#$executeResourceCommand', sourceControlHandle, groupHandle, handle); const sourceControl = this._sourceControls.get(sourceControlHandle); @@ -643,7 +643,7 @@ export class ExtHostSCM implements ExtHostSCMShape { return Promise.resolve(undefined); } - return group.$executeResourceCommand(handle); + return group.$executeResourceCommand(handle, preserveFocus); } $validateInput(sourceControlHandle: number, value: string, cursorPosition: number): Promise<[string, number] | undefined> { diff --git a/src/vs/workbench/contrib/scm/browser/repositoryPane.ts b/src/vs/workbench/contrib/scm/browser/repositoryPane.ts index 5744b660c49..2be16f98815 100644 --- a/src/vs/workbench/contrib/scm/browser/repositoryPane.ts +++ b/src/vs/workbench/contrib/scm/browser/repositoryPane.ts @@ -27,7 +27,7 @@ import { ActionBar, IActionViewItemProvider } from 'vs/base/browser/ui/actionbar import { IThemeService, LIGHT, registerThemingParticipant, IFileIconTheme } from 'vs/platform/theme/common/themeService'; import { isSCMResource, isSCMResourceGroup, connectPrimaryMenuToInlineActionBar } from './util'; import { attachBadgeStyler } from 'vs/platform/theme/common/styler'; -import { WorkbenchCompressibleObjectTree } from 'vs/platform/list/browser/listService'; +import { WorkbenchCompressibleObjectTree, TreeResourceNavigator, IOpenEvent } from 'vs/platform/list/browser/listService'; import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { disposableTimeout, ThrottledDelayer } from 'vs/base/common/async'; import { INotificationService } from 'vs/platform/notification/common/notification'; @@ -877,10 +877,8 @@ export class RepositoryPane extends ViewPane { accessibilityProvider: new SCMAccessibilityProvider() }) as WorkbenchCompressibleObjectTree; - this._register(Event.chain(this.tree.onDidOpen) - .map(e => e.elements[0]) - .filter((e): e is ISCMResource => !!e && !isSCMResourceGroup(e) && !ResourceTree.isResourceNode(e)) - .on(this.open, this)); + const navigator = this._register(new TreeResourceNavigator(this.tree, { openOnSelection: false })); + this._register(navigator.onDidOpenResource(this.open, this)); this._register(Event.chain(this.tree.onDidPin) .map(e => e.elements[0]) @@ -1020,8 +1018,12 @@ export class RepositoryPane extends ViewPane { return this.repository.provider; } - private open(e: ISCMResource): void { - e.open(); + private open(e: IOpenEvent): void { + if (!e.element || isSCMResourceGroup(e.element) || ResourceTree.isResourceNode(e.element)) { + return; + } + + e.element.open(!!e.editorOptions.preserveFocus); } private pin(): void { diff --git a/src/vs/workbench/contrib/scm/common/scm.ts b/src/vs/workbench/contrib/scm/common/scm.ts index cf63ad255d9..d6fd58f1519 100644 --- a/src/vs/workbench/contrib/scm/common/scm.ts +++ b/src/vs/workbench/contrib/scm/common/scm.ts @@ -30,7 +30,7 @@ export interface ISCMResource { readonly resourceGroup: ISCMResourceGroup; readonly sourceUri: URI; readonly decorations: ISCMResourceDecorations; - open(): Promise; + open(preserveFocus: boolean): Promise; } export interface ISCMResourceGroup extends ISequence {