소스 검색

Adds Show in Side Bar for search git command

Removes Show Here/Show in Side Bar toggle from search git command
Changes showResultsInSideBar to be an override if not null
main
Eric Amodio 4 년 전
부모
커밋
6ecdb2f81f
9개의 변경된 파일112개의 추가작업 그리고 99개의 파일을 삭제
  1. +8
    -5
      package.json
  2. +20
    -17
      src/commands/git/search.ts
  3. +0
    -30
      src/commands/quickCommand.buttons.ts
  4. +30
    -11
      src/commands/quickCommand.steps.ts
  5. +3
    -1
      src/commands/searchCommits.ts
  6. +1
    -1
      src/config.ts
  7. +13
    -0
      src/quickpicks/quickPicksItems.ts
  8. +14
    -14
      src/views/nodes/compareResultsNode.ts
  9. +23
    -20
      src/views/nodes/searchResultsNode.ts

+ 8
- 5
package.json 파일 보기

@ -599,9 +599,12 @@
"markdownDeprecationMessage": "Depreciated: This setting has been renamed to `#gitlens.gitCommands.search.showResultsInSideBar#`"
},
"gitlens.gitCommands.search.showResultsInSideBar": {
"type": "boolean",
"default": false,
"markdownDescription": "Specifies whether to show the commit search results in the Side Bar or within the quick pick menu",
"type": [
"boolean",
"null"
],
"default": null,
"markdownDescription": "Specifies whether to show the commit search results directly in the quick pick menu, in the Side Bar, or will be based on the context",
"scope": "window"
},
"gitlens.gitCommands.skipConfirmations": {
@ -7200,12 +7203,12 @@
},
{
"command": "gitlens.views.searchAndCompare.edit",
"when": "viewItem == gitlens:search:results",
"when": "viewItem =~ /gitlens:search:results\\b/",
"group": "inline@1"
},
{
"command": "gitlens.views.searchAndCompare.edit",
"when": "viewItem == gitlens:search:results",
"when": "viewItem =~ /gitlens:search:results\\b/",
"group": "1_gitlens_actions@1"
},
{

+ 20
- 17
src/commands/git/search.ts 파일 보기

@ -17,7 +17,7 @@ import {
StepSelection,
StepState,
} from '../quickCommand';
import { QuickPickItemOfT } from '../../quickpicks';
import { ActionQuickPickItem, QuickPickItemOfT } from '../../quickpicks';
import { Strings } from '../../system';
interface Context {
@ -105,7 +105,7 @@ export class SearchGitCommand extends QuickCommand {
state.matchRegex = cfg.matchRegex;
}
if (state.showResultsInSideBar == null) {
state.showResultsInSideBar = cfg.showResultsInSideBar;
state.showResultsInSideBar = cfg.showResultsInSideBar ?? undefined;
}
let skippedStepOne = false;
@ -188,6 +188,23 @@ export class SearchGitCommand extends QuickCommand {
number: log.hasMore ? `${log.count}+` : undefined,
})} for ${state.pattern}`,
picked: context.commit?.ref,
showInSideBarCommand: new ActionQuickPickItem(
'$(link-external) Show Results in Side Bar',
() =>
void Container.searchAndCompareView.search(
repoPath,
search,
{
label: { label: `for ${state.pattern}` },
reveal: {
select: true,
focus: false,
expand: true,
},
},
context.resultsPromise,
),
),
showInSideBarButton: {
button: QuickCommandButtons.ShowResultsInSideBar,
onDidClick: () =>
@ -266,26 +283,12 @@ export class SearchGitCommand extends QuickCommand {
const matchAllButton = new QuickCommandButtons.MatchAllToggle(state.matchAll);
const matchRegexButton = new QuickCommandButtons.MatchRegexToggle(state.matchRegex);
const additionalButtons = [matchCaseButton, matchAllButton, matchRegexButton];
if (!SearchResultsNode.is(state.showResultsInSideBar)) {
const showResultsToggleButton = new QuickCommandButtons.ShowResultsToggle(
state.showResultsInSideBar,
() => {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
state.showResultsInSideBar = !state.showResultsInSideBar;
showResultsToggleButton.on = state.showResultsInSideBar;
},
);
additionalButtons.push(showResultsToggleButton);
}
const step = QuickCommand.createPickStep<QuickPickItemOfT<SearchOperators>>({
title: appendReposToTitle(context.title, state, context),
placeholder: 'e.g. "Updates dependencies" author:eamodio',
matchOnDescription: true,
matchOnDetail: true,
additionalButtons: additionalButtons,
additionalButtons: [matchCaseButton, matchAllButton, matchRegexButton],
items: items,
value: state.pattern,
onDidAccept: (quickpick): boolean => {

+ 0
- 30
src/commands/quickCommand.buttons.ts 파일 보기

@ -112,32 +112,6 @@ export namespace QuickCommandButtons {
tooltip: 'Show Results in Side Bar',
};
export const ShowResultsToggle = class extends ToggleQuickInputButton {
constructor(on = false, onDidClick?: (quickInput: QuickInput) => void) {
super(
() => ({
on: {
tooltip: 'Show Results in Side Bar',
icon: {
dark: Uri.file(Container.context.asAbsolutePath('images/dark/icon-window.svg')),
light: Uri.file(Container.context.asAbsolutePath('images/light/icon-window.svg')),
},
},
off: {
tooltip: 'Show Results Here',
icon: {
dark: Uri.file(Container.context.asAbsolutePath('images/dark/icon-window-disabled.svg')),
light: Uri.file(Container.context.asAbsolutePath('images/light/icon-window-disabled.svg')),
},
},
}),
on,
);
this.onDidClick = onDidClick;
}
};
export const ShowTagsToggle = class extends SelectableQuickInputButton {
constructor(on = false) {
super('Show Tags', 'tag', on);
@ -146,10 +120,6 @@ export namespace QuickCommandButtons {
export const WillConfirmForced: QuickInputButton = {
iconPath: new ThemeIcon('check'),
// iconPath: {
// dark: Uri.file(Container.context.asAbsolutePath('images/dark/icon-check.svg')),
// light: Uri.file(Container.context.asAbsolutePath('images/light/icon-check.svg')),
// },
tooltip: 'Will always confirm',
};

+ 30
- 11
src/commands/quickCommand.steps.ts 파일 보기

@ -728,7 +728,7 @@ export async function* pickBranchOrTagStepMultiRepo<
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
}
export function* pickCommitStep<
export async function* pickCommitStep<
State extends PartialStepState & { repo: Repository },
Context extends { repos: Repository[]; title: string }
>(
@ -740,6 +740,7 @@ export function* pickCommitStep<
onDidLoadMore,
picked,
placeholder,
showInSideBarCommand,
showInSideBarButton: showInSideBar,
titleContext,
}: {
@ -748,6 +749,7 @@ export function* pickCommitStep<
onDidLoadMore?: (log: GitLog | undefined) => void;
picked?: string | string[] | undefined;
placeholder: string | ((context: Context, log: GitLog | undefined) => string);
showInSideBarCommand?: CommandQuickPickItem;
showInSideBarButton?: {
button: QuickInputButton;
onDidClick: (items: Readonly<CommitQuickPickItem<GitLogCommit>[]>) => void;
@ -771,14 +773,14 @@ export function* pickCommitStep<
];
}
const step = QuickCommand.createPickStep<CommitQuickPickItem>({
const step = QuickCommand.createPickStep<CommandQuickPickItem | CommitQuickPickItem>({
title: appendReposToTitle(`${context.title}${titleContext ?? ''}`, state, context),
placeholder: typeof placeholder === 'string' ? placeholder : placeholder(context, log),
ignoreFocusOut: ignoreFocusOut,
matchOnDescription: true,
matchOnDetail: true,
value: typeof picked === 'string' && log?.count === 0 ? picked : undefined,
items: getItems(log),
items: showInSideBarCommand != null ? [showInSideBarCommand, ...getItems(log)] : getItems(log),
onDidLoadMore: async quickpick => {
log = await log?.more?.(configuration.get('advanced', 'maxListItems'));
onDidLoadMore?.(log);
@ -795,16 +797,20 @@ export function* pickCommitStep<
onDidClickButton: (quickpick, button) => {
if (log == null) return;
const items = quickpick.activeItems.filter<CommitQuickPickItem<GitLogCommit>>(
(i): i is CommitQuickPickItem<GitLogCommit> => !CommandQuickPickItem.is(i),
);
if (button === showInSideBar?.button) {
showInSideBar.onDidClick(quickpick.activeItems);
showInSideBar.onDidClick(items);
return;
}
if (quickpick.activeItems.length === 0 || log == null) return;
if (items.length === 0 || log == null) return;
if (button === QuickCommandButtons.RevealInSideBar) {
void GitActions.Commit.reveal(quickpick.activeItems[0].item, {
void GitActions.Commit.reveal(items[0].item, {
select: true,
focus: false,
expand: true,
@ -816,10 +822,10 @@ export function* pickCommitStep<
if (button === QuickCommandButtons.SearchInSideBar) {
void Container.searchAndCompareView.search(
state.repo.path,
{ pattern: SearchPattern.fromCommit(quickpick.activeItems[0].item.ref) },
{ pattern: SearchPattern.fromCommit(items[0].item.ref) },
{
label: {
label: `for ${GitReference.toString(quickpick.activeItems[0].item, { icon: false })}`,
label: `for ${GitReference.toString(items[0].item, { icon: false })}`,
},
reveal: {
select: true,
@ -834,14 +840,18 @@ export function* pickCommitStep<
onDidPressKey: async (quickpick, key) => {
if (quickpick.activeItems.length === 0) return;
const items = quickpick.activeItems.filter<CommitQuickPickItem<GitLogCommit>>(
(i): i is CommitQuickPickItem<GitLogCommit> => !CommandQuickPickItem.is(i),
);
if (key === 'ctrl+right') {
await GitActions.Commit.reveal(quickpick.activeItems[0].item, {
await GitActions.Commit.reveal(items[0].item, {
select: true,
focus: false,
expand: true,
});
} else {
const commit = quickpick.activeItems[0].item;
const commit = items[0].item;
await Container.searchAndCompareView.search(
commit.repoPath,
{ pattern: SearchPattern.fromCommit(commit) },
@ -859,7 +869,16 @@ export function* pickCommitStep<
onValidateValue: getValidateGitReferenceFn(state.repo),
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
if (!QuickCommand.canPickStepContinue(step, state, selection)) return StepResult.Break;
if (CommandQuickPickItem.is(selection[0])) {
QuickCommand.endSteps(state);
await selection[0].execute();
return StepResult.Break;
}
return selection[0].item;
}
export function* pickCommitsStep<

+ 3
- 1
src/commands/searchCommits.ts 파일 보기

@ -1,6 +1,7 @@
'use strict';
import { executeGitCommand } from '../commands';
import { Command, command, CommandContext, Commands, isCommandViewContextWithRepo } from './common';
import { Container } from '../container';
import { SearchPattern } from '../git/git';
import { SearchResultsNode } from '../views/nodes';
@ -48,7 +49,8 @@ export class SearchCommitsCommand extends Command {
state: {
repo: args?.repoPath,
...args?.search,
showResultsInSideBar: args?.showResultsInSideBar,
showResultsInSideBar:
Container.config.gitCommands.search.showResultsInSideBar ?? args?.showResultsInSideBar,
},
}));
}

+ 1
- 1
src/config.ts 파일 보기

@ -52,7 +52,7 @@ export interface Config {
matchAll: boolean;
matchCase: boolean;
matchRegex: boolean;
showResultsInSideBar: boolean;
showResultsInSideBar: boolean | null;
};
skipConfirmations: string[];
};

+ 13
- 0
src/quickpicks/quickPicksItems.ts 파일 보기

@ -160,6 +160,19 @@ export class CommandQuickPickItem implements Qu
}
}
export class ActionQuickPickItem extends CommandQuickPickItem {
constructor(
labelOrItem: string | QuickPickItem,
private readonly action: (options?: { preserveFocus?: boolean; preview?: boolean }) => void | Promise<void>,
) {
super(labelOrItem, undefined, undefined);
}
async execute(options?: { preserveFocus?: boolean; preview?: boolean }): Promise<void> {
return this.action(options);
}
}
export type FlagsQuickPickItem<T> = QuickPickItemOfT<T[]>;
export namespace FlagsQuickPickItem {
export function create<T>(flags: T[], item: T[], options: QuickPickItem) {

+ 14
- 14
src/views/nodes/compareResultsNode.ts 파일 보기

@ -145,13 +145,8 @@ export class CompareResultsNode extends ViewNode {
if (this.pinned) return;
this._pinned = Date.now();
await this.view.updatePinned(this.getPinnableId(), {
type: 'comparison',
timestamp: this._pinned,
path: this.repoPath,
ref1: this._ref,
ref2: this._compareWith,
});
await this.updatePinned();
setImmediate(() => this.view.reveal(this, { focus: true, select: true }));
}
@ -175,13 +170,7 @@ export class CompareResultsNode extends ViewNode {
// If we were pinned, remove the existing pin and save a new one
if (this.pinned) {
await this.view.updatePinned(currentId);
await this.view.updatePinned(this.getPinnableId(), {
type: 'comparison',
timestamp: this._pinned,
path: this.repoPath,
ref1: this._ref,
ref2: this._compareWith,
});
await this.updatePinned();
}
this._children = undefined;
@ -195,6 +184,7 @@ export class CompareResultsNode extends ViewNode {
this._pinned = 0;
await this.view.updatePinned(this.getPinnableId());
setImmediate(() => this.view.reveal(this, { focus: true, select: true }));
}
@ -284,4 +274,14 @@ export class CompareResultsNode extends ViewNode {
return results as CommitsQueryResults;
};
}
private updatePinned() {
return this.view.updatePinned(this.getPinnableId(), {
type: 'comparison',
timestamp: this._pinned,
path: this.repoPath,
ref1: this._ref,
ref2: this._compareWith,
});
}
}

+ 23
- 20
src/views/nodes/searchResultsNode.ts 파일 보기

@ -139,19 +139,6 @@ export class SearchResultsNode extends ViewNode implements
item.iconPath = new ThemeIcon('pinned');
}
// if (item.collapsibleState === TreeItemCollapsibleState.None) {
// const args: SearchCommitsCommandArgs = {
// search: this.search,
// prefillOnly: true,
// showResultsInSideBar: true,
// };
// item.command = {
// title: 'Search Commits',
// command: Commands.SearchCommitsInView,
// arguments: [args],
// };
// }
return item;
}
@ -191,12 +178,22 @@ export class SearchResultsNode extends ViewNode implements
return;
}
// Save the current id so we can update it later
const currentId = this.getPinnableId();
this._search = search.pattern;
this._labels = search.labels;
this._searchQueryOrLog = search.log;
this._resultsNode = undefined;
// If we were pinned, remove the existing pin and save a new one
if (this.pinned) {
await this.view.updatePinned(currentId);
await this.updatePinned();
}
void this.triggerChange(false);
setImmediate(() => this.view.reveal(this, { expand: true, focus: true, select: true }));
}
@gate()
@ -210,13 +207,8 @@ export class SearchResultsNode extends ViewNode implements
if (this.pinned) return;
this._pinned = Date.now();
await this.view.updatePinned(this.getPinnableId(), {
type: 'search',
timestamp: this._pinned,
path: this.repoPath,
labels: this._labels,
search: this.search,
});
await this.updatePinned();
setImmediate(() => this.view.reveal(this, { focus: true, select: true }));
}
@ -226,6 +218,7 @@ export class SearchResultsNode extends ViewNode implements
this._pinned = 0;
await this.view.updatePinned(this.getPinnableId());
setImmediate(() => this.view.reveal(this, { focus: true, select: true }));
}
@ -294,4 +287,14 @@ export class SearchResultsNode extends ViewNode implements
return results;
};
}
private updatePinned() {
return this.view.updatePinned(this.getPinnableId(), {
type: 'search',
timestamp: this._pinned,
path: this.repoPath,
labels: this._labels,
search: this.search,
});
}
}

불러오는 중...
취소
저장