Skip to content

Commit 48b5b7d

Browse files
committed
Add option to open file on click in Search & Compare view
1 parent d7aee42 commit 48b5b7d

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Added the option to open a file instead of showing a diff when clicking in _Search & Compare_
12+
- Closes [#1651](https://github.com/gitkraken/vscode-gitlens/issues/1651)
13+
914
### Fixed
1015

1116
- Fixes [#3582](https://github.com/gitkraken/vscode-gitlens/issues/3582) - "Delete Branch" option is sometimes unexpectedly missing

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ A big thanks to the people that have contributed to this project 🙏❤️:
447447
- may ([@m4rch3n1ng](https://github.com/m4rch3n1ng)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=m4rch3n1ng)
448448
- bm-w ([@bm-w](https://github.com/bm-w)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=bm-w)
449449
- Tyler Johnson ([@TJohnsonSE](https://github.com/TJohnsonSE)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=TJohnsonSE)
450+
- Ehab Younes ([@EhabY](https://github.com/EhabY)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=EhabY)
450451

451452
Also special thanks to the people that have provided support, testing, brainstorming, etc:
452453

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,6 +2864,13 @@
28642864
"scope": "window",
28652865
"order": 22
28662866
},
2867+
"gitlens.views.searchAndCompare.files.openDiffOnClick": {
2868+
"type": "boolean",
2869+
"default": "true",
2870+
"markdownDescription": "Specifies whether to open the diff view or the file itself when clicking on a file in the _Search & Compare_ view",
2871+
"scope": "window",
2872+
"order": 23
2873+
},
28672874
"gitlens.views.searchAndCompare.files.icon": {
28682875
"type": "string",
28692876
"default": "type",

src/commands/openFileAtRevision.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
101101
}
102102

103103
async execute(editor: TextEditor | undefined, uri?: Uri, args?: OpenFileAtRevisionCommandArgs) {
104-
uri = getCommandUri(uri, editor);
105-
if (uri == null) return;
106-
107-
const gitUri = await GitUri.fromUri(uri);
108-
109104
args = { ...args };
110105
if (args.line == null) {
111106
args.line = editor?.selection.active.line ?? 0;
112107
}
113108

114109
try {
115110
if (args.revisionUri == null) {
111+
uri = getCommandUri(uri, editor);
112+
if (uri == null) return;
113+
114+
const gitUri = await GitUri.fromUri(uri);
115+
116116
const log = this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath).then(
117117
log =>
118118
log ??

src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,9 @@ export interface RepositoriesViewConfig {
817817

818818
export interface SearchAndCompareViewConfig {
819819
readonly avatars: boolean;
820-
readonly files: ViewsFilesConfig;
820+
readonly files: ViewsFilesConfig & {
821+
readonly openDiffOnClick: boolean;
822+
};
821823
readonly pullRequests: {
822824
readonly enabled: boolean;
823825
readonly showForCommits: boolean;

src/views/nodes/commitFileNode.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { Command, Selection } from 'vscode';
1+
import type { Command, Selection, TextDocumentShowOptions } from 'vscode';
22
import { MarkdownString, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
33
import type { DiffWithPreviousCommandArgs } from '../../commands/diffWithPrevious';
4+
import type { OpenFileAtRevisionCommandArgs } from '../../commands/openFileAtRevision';
45
import { Schemes } from '../../constants';
56
import { Commands } from '../../constants.commands';
67
import type { TreeViewRefFileNodeTypes } from '../../constants.views';
@@ -175,14 +176,30 @@ export abstract class CommitFileNodeBase<
175176
line = this.options?.selection?.active.line ?? 0;
176177
}
177178

179+
const showOptions: TextDocumentShowOptions = {
180+
preserveFocus: true,
181+
preview: true,
182+
};
183+
184+
const filesConfig = this.view.config.files;
185+
if ('openDiffOnClick' in filesConfig && filesConfig.openDiffOnClick === false) {
186+
const commandArgs: OpenFileAtRevisionCommandArgs = {
187+
revisionUri: GitUri.fromFile(this.file, this.commit.repoPath, this.ref.ref),
188+
line: line,
189+
showOptions: showOptions,
190+
};
191+
return {
192+
title: 'Open File',
193+
command: Commands.OpenFileAtRevision,
194+
arguments: [commandArgs],
195+
};
196+
}
197+
178198
const commandArgs: DiffWithPreviousCommandArgs = {
179199
commit: this.commit,
180200
uri: GitUri.fromFile(this.file, this.commit.repoPath),
181201
line: line,
182-
showOptions: {
183-
preserveFocus: true,
184-
preview: true,
185-
},
202+
showOptions: showOptions,
186203
};
187204
return {
188205
title: 'Open Changes with Previous Revision',

src/webviews/apps/settings/partials/views.searchAndCompare.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ <h2>
114114
<p class="setting__hint">Compacts (flattens) unnecessary nesting when using a tree layouts</p>
115115
</div>
116116

117+
<div class="setting">
118+
<div class="setting__input">
119+
<input
120+
id="views.searchAndCompare.files.openDiffOnClick"
121+
name="views.searchAndCompare.files.openDiffOnClick"
122+
type="checkbox"
123+
data-setting
124+
/>
125+
<label for="views.searchAndCompare.files.openDiffOnClick">Open file diff on click</label>
126+
</div>
127+
<p class="setting__hint">
128+
Opens the diff view when clicking on a file instead of opening the file itself
129+
</p>
130+
</div>
131+
117132
<div class="setting">
118133
<div class="setting__input">
119134
<input

0 commit comments

Comments
 (0)