Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1651 - Adds an option to open a file on click in Search & Compare #3583

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Adds Holiday promotion
- Adds the ability to get autolinks for branches via the branch name — closes [#3547](https://github.com/gitkraken/vscode-gitlens/issues/3547)
- Adds GitLab issues to the issues list in the _Start Work_ command when GitLab is connected — closes [#3779](https://github.com/gitkraken/vscode-gitlens/issues/3779)
- Adds the option to open a file instead of showing a diff when clicking in _Search & Compare_ — closes [#1651](https://github.com/gitkraken/vscode-gitlens/issues/1651)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ A big thanks to the people that have contributed to this project 🙏❤️:
- Jean Pierre ([@jeanp413](https://github.com/jeanp413)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=jeanp413)
- Dawn Hwang ([@hwangh95](https://github.com/hwangh95)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=hwangh95)
- Emmanuel Ferdman ([@emmanuel-ferdman](https://github.com/emmanuel-ferdman)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=emmanuel-ferdman)
- 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:

Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,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",
Expand Down
10 changes: 5 additions & 5 deletions src/commands/openFileAtRevision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
}

async execute(editor: TextEditor | undefined, uri?: Uri, args?: OpenFileAtRevisionCommandArgs) {
uri = getCommandUri(uri, editor);
if (uri == null) return;

const gitUri = await GitUri.fromUri(uri);

args = { ...args };
if (args.line == null) {
args.line = editor?.selection.active.line ?? 0;
}

try {
if (args.revisionUri == null) {
uri = getCommandUri(uri, editor);
if (uri == null) return;

const gitUri = await GitUri.fromUri(uri);

const log = this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath).then(
log =>
log ??
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,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;
Expand Down
27 changes: 22 additions & 5 deletions src/views/nodes/commitFileNode.ts
Original file line number Diff line number Diff line change
@@ -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 { Commands } from '../../constants.commands';
import type { TreeViewRefFileNodeTypes } from '../../constants.views';
Expand Down Expand Up @@ -164,14 +165,30 @@ export abstract class CommitFileNodeBase<
line = this.options?.selection?.active.line ?? 0;
}

const showOptions: TextDocumentShowOptions = {
preserveFocus: true,
preview: true,
};

const filesConfig = this.view.config.files;
if ('openDiffOnClick' in filesConfig && filesConfig.openDiffOnClick === false) {
const commandArgs: OpenFileAtRevisionCommandArgs = {
revisionUri: GitUri.fromFile(this.file, this.commit.repoPath, this.ref.ref),
line: line,
showOptions: showOptions,
};
return {
title: 'Open File',
command: Commands.OpenFileAtRevision,
arguments: [commandArgs],
};
}

const commandArgs: DiffWithPreviousCommandArgs = {
commit: this.commit,
uri: GitUri.fromFile(this.file, this.commit.repoPath),
line: line,
showOptions: {
preserveFocus: true,
preview: true,
},
showOptions: showOptions,
};
return {
title: 'Open Changes with Previous Revision',
Expand Down
15 changes: 15 additions & 0 deletions src/webviews/apps/settings/partials/views.searchAndCompare.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ <h2>
<p class="setting__hint">Compacts (flattens) unnecessary nesting when using a tree layouts</p>
</div>

<div class="setting">
<div class="setting__input">
<input
id="views.searchAndCompare.files.openDiffOnClick"
name="views.searchAndCompare.files.openDiffOnClick"
type="checkbox"
data-setting
/>
<label for="views.searchAndCompare.files.openDiffOnClick">Open file diff on click</label>
</div>
<p class="setting__hint">
Opens the diff view when clicking on a file instead of opening the file itself
</p>
</div>

<div class="setting">
<div class="setting__input">
<input
Expand Down