Skip to content

Commit 99bf1c5

Browse files
committed
Improves the commit search experience
Remembers and restores the last commit search string Adds search command to the results inline toolbar Reopens search when clicking on a result node with no results Fixes encoded html in empty state
1 parent 7b85b2e commit 99bf1c5

File tree

9 files changed

+126
-25
lines changed

9 files changed

+126
-25
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
9+
### Added
10+
11+
- Improves the commit search experience
12+
- Remembers and restores the last commit search string
13+
- Adds the _Search Commits_ command to the search results inline toolbar
14+
- Reopens the commit search when clicking on a search results without results
15+
16+
### Fixed
17+
18+
- Fixes html encoding issues with the _Search Commits_ view empty state
19+
720
## [9.1.0] - 2018-12-12
821

922
### Added

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,11 +4127,6 @@
41274127
"when": "viewItem == gitlens:repository",
41284128
"group": "8_gitlens@1"
41294129
},
4130-
{
4131-
"command": "gitlens.views.compare.swapComparision",
4132-
"when": "viewItem == gitlens:compare:results",
4133-
"group": "inline@1"
4134-
},
41354130
{
41364131
"command": "gitlens.views.dismissNode",
41374132
"when": "viewItem =~ /gitlens:(compare:picker:ref|compare|search)\\b(?!:(commits|files))/",
@@ -4142,6 +4137,11 @@
41424137
"when": "viewItem =~ /gitlens:(compare:picker:ref|compare|search)\\b(?!:(commits|files))/",
41434138
"group": "1_gitlens@1"
41444139
},
4140+
{
4141+
"command": "gitlens.views.compare.swapComparision",
4142+
"when": "viewItem == gitlens:compare:results",
4143+
"group": "inline@1"
4144+
},
41454145
{
41464146
"command": "gitlens.views.compare.swapComparision",
41474147
"when": "viewItem == gitlens:compare:results",
@@ -4152,6 +4152,16 @@
41524152
"when": "viewItem == gitlens:compare:results",
41534153
"group": "7_gitlens@1"
41544154
},
4155+
{
4156+
"command": "gitlens.views.search.searchCommits",
4157+
"when": "viewItem == gitlens:search:results",
4158+
"group": "inline@1"
4159+
},
4160+
{
4161+
"command": "gitlens.views.search.searchCommits",
4162+
"when": "viewItem == gitlens:search:results",
4163+
"group": "2_gitlens@1"
4164+
},
41554165
{
41564166
"command": "gitlens.stashApply",
41574167
"when": "!gitlens:readonly && viewItem == gitlens:stashes",

src/commands/searchCommits.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Logger } from '../logger';
77
import { Messages } from '../messages';
88
import { CommandQuickPickItem, CommitsQuickPick, ShowCommitSearchResultsInViewQuickPickItem } from '../quickpicks';
99
import { Iterables, Strings } from '../system';
10+
import { SearchResultsCommitsNode } from '../views/nodes';
1011
import {
1112
ActiveEditorCachedCommand,
1213
command,
@@ -39,13 +40,16 @@ export interface SearchCommitsCommandArgs {
3940
search?: string;
4041
searchBy?: GitRepoSearchBy;
4142
maxCount?: number;
43+
prefillOnly?: boolean;
4244
showInView?: boolean;
4345

4446
goBackCommand?: CommandQuickPickItem;
4547
}
4648

4749
@command()
4850
export class SearchCommitsCommand extends ActiveEditorCachedCommand {
51+
private _lastSearch: string | undefined;
52+
4953
constructor() {
5054
super([Commands.SearchCommits, Commands.SearchCommitsInView]);
5155
}
@@ -55,6 +59,12 @@ export class SearchCommitsCommand extends ActiveEditorCachedCommand {
5559
args = { ...args };
5660
args.showInView = true;
5761

62+
if (context.node instanceof SearchResultsCommitsNode) {
63+
args.search = context.node.search;
64+
args.searchBy = context.node.searchBy;
65+
args.prefillOnly = true;
66+
}
67+
5868
if (isCommandViewContextWithRepo(context)) {
5969
return this.execute(context.editor, context.node.uri, args);
6070
}
@@ -86,11 +96,21 @@ export class SearchCommitsCommand extends ActiveEditorCachedCommand {
8696
args = { ...args };
8797
const originalArgs = { ...args };
8898

99+
if (args.prefillOnly && args.search && args.searchBy) {
100+
args.search = `${searchByToSymbolMap.get(args.searchBy) || ''}${args.search}`;
101+
args.searchBy = undefined;
102+
}
103+
89104
if (!args.search || args.searchBy == null) {
90105
let selection;
91-
if (!args.search && args.searchBy != null) {
92-
args.search = searchByToSymbolMap.get(args.searchBy);
93-
selection = [1, 1];
106+
if (!args.search) {
107+
if (args.searchBy != null) {
108+
args.search = searchByToSymbolMap.get(args.searchBy);
109+
selection = [1, 1];
110+
}
111+
else {
112+
args.search = this._lastSearch;
113+
}
94114
}
95115

96116
if (args.showInView) {
@@ -107,7 +127,7 @@ export class SearchCommitsCommand extends ActiveEditorCachedCommand {
107127
return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
108128
}
109129

110-
originalArgs.search = args.search;
130+
this._lastSearch = originalArgs.search = args.search;
111131

112132
const match = searchByRegex.exec(args.search);
113133
if (match && match[1]) {
@@ -198,7 +218,9 @@ export class SearchCommitsCommand extends ActiveEditorCachedCommand {
198218
: undefined,
199219
showInViewCommand:
200220
log !== undefined
201-
? new ShowCommitSearchResultsInViewQuickPickItem(log, { label: searchLabel! })
221+
? new ShowCommitSearchResultsInViewQuickPickItem(args.search, args.searchBy, log, {
222+
label: searchLabel!
223+
})
202224
: undefined
203225
});
204226
if (pick === undefined) return undefined;

src/quickpicks/commonQuickPicks.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { GlyphChars } from '../constants';
1515
import { Container } from '../container';
1616
import { GitLog, GitLogCommit, GitRepoSearchBy, GitStashCommit, GitUri } from '../git/gitService';
1717
import { KeyMapping, Keys } from '../keyboard';
18-
import { Functions, Strings } from '../system';
18+
import { Strings } from '../system';
1919
import {
2020
BranchesAndTagsQuickPick,
2121
BranchQuickPickItem,
@@ -243,6 +243,8 @@ export class ShowCommitInViewQuickPickItem extends CommandQuickPickItem {
243243

244244
export class ShowCommitSearchResultsInViewQuickPickItem extends CommandQuickPickItem {
245245
constructor(
246+
public readonly search: string,
247+
public readonly searchBy: GitRepoSearchBy,
246248
public readonly results: GitLog,
247249
public readonly resultsLabel: string | { label: string; resultsType?: { singular: string; plural: string } },
248250
item: QuickPickItem = {
@@ -258,7 +260,9 @@ export class ShowCommitSearchResultsInViewQuickPickItem extends CommandQuickPick
258260
}
259261

260262
async execute(): Promise<{} | undefined> {
261-
await Container.searchView.showSearchResults(this.results.repoPath, this.results, { label: this.resultsLabel });
263+
await Container.searchView.showSearchResults(this.results.repoPath, this.search, this.searchBy, this.results, {
264+
label: this.resultsLabel
265+
});
262266
return undefined;
263267
}
264268
}

src/views/nodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export * from './nodes/resultsCommitsNode';
2020
export * from './nodes/resultsFileNode';
2121
export * from './nodes/resultsFilesNode';
2222
export * from './nodes/searchNode';
23+
export * from './nodes/searchResultsCommitsNode';
2324
export * from './nodes/stashesNode';
2425
export * from './nodes/stashFileNode';
2526
export * from './nodes/stashNode';

src/views/nodes/resultsCommitsNode.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ export class ResultsCommitsNode extends ViewNode implements PageableViewNode {
2121
view: View,
2222
parent: ViewNode,
2323
public readonly repoPath: string,
24-
private readonly _commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults>,
25-
private readonly _contextValue: ResourceType = ResourceType.ResultsCommits
24+
private readonly _commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults>
2625
) {
2726
super(GitUri.fromRepoPath(repoPath), view, parent);
2827
}
2928

29+
get type(): ResourceType {
30+
return ResourceType.ResultsCommits;
31+
}
32+
3033
async getChildren(): Promise<ViewNode[]> {
3134
const { log } = await this.getCommitsQueryResults();
3235
if (log === undefined) return [];
@@ -56,7 +59,7 @@ export class ResultsCommitsNode extends ViewNode implements PageableViewNode {
5659
label,
5760
log && log.count > 0 ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None
5861
);
59-
item.contextValue = this._contextValue;
62+
item.contextValue = this.type;
6063

6164
return item;
6265
}
@@ -67,7 +70,7 @@ export class ResultsCommitsNode extends ViewNode implements PageableViewNode {
6770

6871
private _commitsQueryResults: Promise<CommitsQueryResults> | undefined;
6972

70-
private getCommitsQueryResults() {
73+
protected getCommitsQueryResults() {
7174
if (this._commitsQueryResults === undefined) {
7275
this._commitsQueryResults = this._commitsQuery(this.maxCount);
7376
}

src/views/nodes/searchNode.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class SearchNode extends ViewNode {
3030
...command,
3131
arguments: [this, { searchBy: GitRepoSearchBy.Message } as SearchCommitsCommandArgs]
3232
},
33-
`Search commits by message (use &lt;message-pattern&gt;)`,
33+
`Search commits by message (use <message-pattern>)`,
3434
'Click to search commits by message'
3535
),
3636
new CommandMessageNode(
@@ -40,7 +40,7 @@ export class SearchNode extends ViewNode {
4040
...command,
4141
arguments: [this, { searchBy: GitRepoSearchBy.Author } as SearchCommitsCommandArgs]
4242
},
43-
`${GlyphChars.Space.repeat(4)} or, by author (use @&lt;author-pattern&gt;)`,
43+
`${GlyphChars.Space.repeat(4)} or, by author (use @<author-pattern>)`,
4444
'Click to search commits by author'
4545
),
4646
new CommandMessageNode(
@@ -50,7 +50,7 @@ export class SearchNode extends ViewNode {
5050
...command,
5151
arguments: [this, { searchBy: GitRepoSearchBy.Sha } as SearchCommitsCommandArgs]
5252
},
53-
`${GlyphChars.Space.repeat(4)} or, by commit id (use #&lt;sha&gt;)`,
53+
`${GlyphChars.Space.repeat(4)} or, by commit id (use #<sha>)`,
5454
'Click to search commits by commit id'
5555
),
5656
new CommandMessageNode(
@@ -60,7 +60,7 @@ export class SearchNode extends ViewNode {
6060
...command,
6161
arguments: [this, { searchBy: GitRepoSearchBy.Files } as SearchCommitsCommandArgs]
6262
},
63-
`${GlyphChars.Space.repeat(4)} or, by files (use :&lt;file-path/glob&gt;)`,
63+
`${GlyphChars.Space.repeat(4)} or, by files (use :<file-path/glob>)`,
6464
'Click to search commits by files'
6565
),
6666
new CommandMessageNode(
@@ -70,7 +70,7 @@ export class SearchNode extends ViewNode {
7070
...command,
7171
arguments: [this, { searchBy: GitRepoSearchBy.Changes } as SearchCommitsCommandArgs]
7272
},
73-
`${GlyphChars.Space.repeat(4)} or, by changes (use =&lt;pattern&gt;)`,
73+
`${GlyphChars.Space.repeat(4)} or, by changes (use =<pattern>)`,
7474
'Click to search commits by changes'
7575
),
7676
new CommandMessageNode(
@@ -80,7 +80,7 @@ export class SearchNode extends ViewNode {
8080
...command,
8181
arguments: [this, { searchBy: GitRepoSearchBy.ChangedLines } as SearchCommitsCommandArgs]
8282
},
83-
`${GlyphChars.Space.repeat(4)} or, by changed lines (use ~&lt;pattern&gt;)`,
83+
`${GlyphChars.Space.repeat(4)} or, by changed lines (use ~<pattern>)`,
8484
'Click to search commits by changed lines'
8585
)
8686
];
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
import { TreeItem } from 'vscode';
3+
import { SearchCommitsCommandArgs } from '../../commands';
4+
import { Commands } from '../../commands/common';
5+
import { GitRepoSearchBy } from '../../git/gitService';
6+
import { View } from '../viewBase';
7+
import { CommitsQueryResults, ResultsCommitsNode } from './resultsCommitsNode';
8+
import { ResourceType, ViewNode } from './viewNode';
9+
10+
export class SearchResultsCommitsNode extends ResultsCommitsNode {
11+
constructor(
12+
view: View,
13+
parent: ViewNode,
14+
repoPath: string,
15+
public readonly search: string,
16+
public readonly searchBy: GitRepoSearchBy,
17+
commitsQuery: (maxCount: number | undefined) => Promise<CommitsQueryResults>
18+
) {
19+
super(view, parent, repoPath, commitsQuery);
20+
}
21+
22+
get type(): ResourceType {
23+
return ResourceType.SearchResults;
24+
}
25+
26+
async getTreeItem(): Promise<TreeItem> {
27+
const { log } = await super.getCommitsQueryResults();
28+
29+
const item = await super.getTreeItem();
30+
31+
if (log == null || log.count === 0) {
32+
const args: SearchCommitsCommandArgs = {
33+
search: this.search,
34+
searchBy: this.searchBy,
35+
prefillOnly: true
36+
};
37+
item.command = {
38+
title: 'Search Commits',
39+
command: Commands.SearchCommitsInView,
40+
arguments: [args]
41+
};
42+
}
43+
44+
return item;
45+
}
46+
}

src/views/searchView.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '.
55
import { Container } from '../container';
66
import { GitLog, GitRepoSearchBy } from '../git/gitService';
77
import { Functions, Strings } from '../system';
8-
import { ResourceType, ResultsCommitsNode, SearchNode, ViewNode } from './nodes';
8+
import { SearchNode, SearchResultsCommitsNode, ViewNode } from './nodes';
99
import { RefreshReason, ViewBase } from './viewBase';
1010

1111
interface SearchQueryResult {
@@ -118,12 +118,14 @@ export class SearchView extends ViewBase<SearchNode> {
118118
);
119119

120120
return this.addResults(
121-
new ResultsCommitsNode(this, this._root!, repoPath, searchQueryFn, ResourceType.SearchResults)
121+
new SearchResultsCommitsNode(this, this._root!, repoPath, search, searchBy, searchQueryFn)
122122
);
123123
}
124124

125125
async showSearchResults(
126126
repoPath: string,
127+
search: string,
128+
searchBy: GitRepoSearchBy,
127129
results: GitLog,
128130
options: {
129131
label:
@@ -141,7 +143,7 @@ export class SearchView extends ViewBase<SearchNode> {
141143
});
142144

143145
return this.addResults(
144-
new ResultsCommitsNode(this, this._root!, repoPath, searchQueryFn, ResourceType.SearchResults)
146+
new SearchResultsCommitsNode(this, this._root!, repoPath, search, searchBy, searchQueryFn)
145147
);
146148
}
147149

0 commit comments

Comments
 (0)