diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f73f51ae068b..5ea03d2b390d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] +### Added + +- Adds the option to open a file instead of showing a diff when clicking in _Search & Compare_ ([#1651](https://github.com/gitkraken/vscode-gitlens/issues/1651)) + ### Changed - Changes branch creation to avoid setting an upstream branch if the new branch name and remote branch name don't match ([#4477](https://github.com/gitkraken/vscode-gitlens/issues/4477)) diff --git a/README.md b/README.md index 18a622d905f5a..a4f1191eacd66 100644 --- a/README.md +++ b/README.md @@ -447,6 +447,7 @@ A big thanks to the people that have contributed to this project 🙏❤️: - Jordon Kashanchi ([@jordonkash](https://github.com/JordonKash)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=jordonkash) - JounQin ([@JounQin](https://github.com/JounQin)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=JounQin) - Noritaka Kobayashi ([@noritaka1166](https://github.com/noritaka1166)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=noritaka1166) +- Ehab Younes ([@EhabY](https://github.com/EhabY)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=EhabY) Also special thanks to the people that have provided support, testing, brainstorming, etc: diff --git a/package.json b/package.json index 0caaf82105eae..a47706d540e21 100644 --- a/package.json +++ b/package.json @@ -3268,6 +3268,13 @@ "scope": "window", "order": 22 }, + "gitlens.views.searchAndCompare.files.openDiffOnClick": { + "type": "boolean", + "default": "true", + "markdownDescription": "Specifies whether to open the diff view or the file itself when clicking on a file in the _Search & Compare_ view", + "scope": "window", + "order": 23 + }, "gitlens.views.searchAndCompare.files.icon": { "type": "string", "default": "type", diff --git a/src/commands/openFileAtRevision.ts b/src/commands/openFileAtRevision.ts index be5d6961aa998..194f539b0be81 100644 --- a/src/commands/openFileAtRevision.ts +++ b/src/commands/openFileAtRevision.ts @@ -105,17 +105,18 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand { } async execute(editor: TextEditor | undefined, uri?: Uri, args?: OpenFileAtRevisionCommandArgs): Promise { - uri = getCommandUri(uri, editor); - if (uri == null) return; - - const gitUri = await GitUri.fromUri(uri); - args = { ...args }; args.range ??= selectionToDiffRange(editor?.selection); - const svc = this.container.git.getRepositoryService(gitUri.repoPath!); try { if (args.revisionUri == null) { + uri = getCommandUri(uri, editor); + if (uri == null) return; + + const gitUri = await GitUri.fromUri(uri); + + const svc = this.container.git.getRepositoryService(gitUri.repoPath!); + const log = svc.commits .getLogForPath(gitUri.fsPath, undefined, { isFolder: false }) .then( diff --git a/src/config.ts b/src/config.ts index c12e7bad4422b..caa94cae0a251 100644 --- a/src/config.ts +++ b/src/config.ts @@ -961,7 +961,9 @@ export interface RepositoriesViewConfig { export interface SearchAndCompareViewConfig { readonly avatars: boolean; - readonly files: ViewsFilesConfig; + readonly files: ViewsFilesConfig & { + readonly openDiffOnClick: boolean; + }; readonly pullRequests: { readonly enabled: boolean; readonly showForCommits: boolean; diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 00eedd4eca259..8d8147ba19a3d 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -1,6 +1,7 @@ -import type { Command, Selection } from 'vscode'; +import type { Command, Selection, TextDocumentShowOptions } from 'vscode'; import { TreeItem, TreeItemCollapsibleState, Uri } from 'vscode'; import type { DiffWithPreviousCommandArgs } from '../../commands/diffWithPrevious'; +import type { OpenFileAtRevisionCommandArgs } from '../../commands/openFileAtRevision'; import { Schemes } from '../../constants'; import type { TreeViewRefFileNodeTypes } from '../../constants.views'; import { StatusFileFormatter } from '../../git/formatters/statusFormatter'; @@ -166,6 +167,21 @@ export abstract class CommitFileNodeBase< range = this.commit.file?.range ?? selectionToDiffRange(this.options?.selection); } + const showOptions: TextDocumentShowOptions = { preserveFocus: true, preview: true }; + + const filesConfig = this.view.config.files; + if ('openDiffOnClick' in filesConfig && filesConfig.openDiffOnClick === false) { + return createCommand<[CommitFileNodeBase, OpenFileAtRevisionCommandArgs]>( + 'gitlens.views.openFileRevision', + 'Open File at Revision', + this, + { + range: range, + showOptions: showOptions, + }, + ); + } + return createCommand<[undefined, DiffWithPreviousCommandArgs]>( 'gitlens.diffWithPrevious', 'Open Changes with Previous Revision', @@ -174,7 +190,7 @@ export abstract class CommitFileNodeBase< commit: this.commit, uri: GitUri.fromFile(this.file, this.commit.repoPath), range: range, - showOptions: { preserveFocus: true, preview: true }, + showOptions: showOptions, }, ); } diff --git a/src/webviews/apps/settings/partials/views.searchAndCompare.html b/src/webviews/apps/settings/partials/views.searchAndCompare.html index 5574ae12d5f11..79ec133efdb04 100644 --- a/src/webviews/apps/settings/partials/views.searchAndCompare.html +++ b/src/webviews/apps/settings/partials/views.searchAndCompare.html @@ -114,6 +114,21 @@

Compacts (flattens) unnecessary nesting when using a tree layouts

+
+
+ + +
+

+ Opens the diff view when clicking on a file instead of opening the file itself +

+
+