Просмотр исходного кода

Adds open search in view option to graph

main
Eric Amodio 2 лет назад
Родитель
Сommit
2b470a94b7
6 измененных файлов: 58 добавлений и 2 удалений
  1. +18
    -0
      src/plus/webviews/graph/graphWebview.ts
  2. +7
    -2
      src/plus/webviews/graph/protocol.ts
  3. +9
    -0
      src/webviews/apps/plus/graph/GraphWrapper.tsx
  4. +6
    -0
      src/webviews/apps/plus/graph/graph.tsx
  5. +1
    -0
      src/webviews/apps/shared/components/search/react.tsx
  6. +17
    -0
      src/webviews/apps/shared/components/search/search-box.ts

+ 18
- 0
src/plus/webviews/graph/graphWebview.ts Просмотреть файл

@ -69,6 +69,7 @@ import type {
GraphComponentConfig,
GraphRepository,
SearchCommitsParams,
SearchOpenInViewParams,
State,
UpdateColumnParams,
UpdateSelectedRepositoryParams,
@ -89,6 +90,7 @@ import {
GetMissingAvatarsCommandType,
GetMoreCommitsCommandType,
SearchCommitsCommandType,
SearchOpenInViewCommandType,
UpdateColumnCommandType,
UpdateSelectedRepositoryCommandType,
UpdateSelectionCommandType,
@ -325,6 +327,9 @@ export class GraphWebview extends WebviewBase {
case SearchCommitsCommandType.method:
onIpc(SearchCommitsCommandType, e, params => this.onSearchCommits(params, e.completionId));
break;
case SearchOpenInViewCommandType.method:
onIpc(SearchOpenInViewCommandType, e, params => this.onSearchOpenInView(params));
break;
case UpdateColumnCommandType.method:
onIpc(UpdateColumnCommandType, e, params => this.onColumnUpdated(params));
break;
@ -619,6 +624,19 @@ export class GraphWebview extends WebviewBase {
);
}
private onSearchOpenInView(e: SearchOpenInViewParams) {
if (this.repository == null) return;
void this.container.searchAndCompareView.search(this.repository.path, e.search, {
label: { label: `for ${e.search.query}` },
reveal: {
select: true,
focus: false,
expand: true,
},
});
}
private onRepositorySelectionChanged(e: UpdateSelectedRepositoryParams) {
this.repository = this.container.git.getRepository(e.path);
}

+ 7
- 2
src/plus/webviews/graph/protocol.ts Просмотреть файл

@ -117,7 +117,12 @@ export interface SearchCommitsParams {
limit?: number;
more?: boolean;
}
export const SearchCommitsCommandType = new IpcCommandType<SearchCommitsParams>('graph/searchCommits');
export const SearchCommitsCommandType = new IpcCommandType<SearchCommitsParams>('graph/search');
export interface SearchOpenInViewParams {
search: SearchQuery;
}
export const SearchOpenInViewCommandType = new IpcCommandType<SearchOpenInViewParams>('graph/search/openInView');
export interface UpdateColumnParams {
name: GraphColumnName;
@ -207,6 +212,6 @@ export interface DidSearchCommitsParams {
selectedRows?: { [id: string]: true };
}
export const DidSearchCommitsNotificationType = new IpcNotificationType<DidSearchCommitsParams>(
'graph/commits/didSearch',
'graph/didSearch',
true,
);

+ 9
- 0
src/webviews/apps/plus/graph/GraphWrapper.tsx Просмотреть файл

@ -43,6 +43,7 @@ export interface GraphWrapperProps extends State {
search: SearchQuery,
options?: { limit?: number; more?: boolean },
) => Promise<DidSearchCommitsParams | undefined>;
onSearchOpenInView?: (search: SearchQuery) => void;
onDismissBanner?: (key: DismissBannerParams['key']) => void;
onSelectionChange?: (selection: { id: string; type: GitGraphRowType }[]) => void;
onEnsureCommitPromise?: (id: string, select: boolean) => Promise<DidEnsureCommitParams | undefined>;
@ -164,6 +165,7 @@ export function GraphWrapper({
onMoreCommits,
onSearchCommits,
onSearchCommitsPromise,
onSearchOpenInView,
onSelectionChange,
nonce,
mixedColumnColors,
@ -358,6 +360,12 @@ export function GraphWrapper({
onSearchCommits?.(isValid ? detail : undefined);
}, 250);
const handleSearchOpenInView = () => {
if (searchQuery == null) return;
onSearchOpenInView?.(searchQuery);
};
useLayoutEffect(() => {
if (mainRef.current === null) return;
@ -630,6 +638,7 @@ export function GraphWrapper({
onChange={e => handleSearchInput(e as CustomEvent<SearchQuery>)}
onPrevious={() => handleSearchNavigation(false)}
onNext={() => handleSearchNavigation(true)}
onOpenInView={() => handleSearchOpenInView()}
/>
</div>
</header>

+ 6
- 0
src/webviews/apps/plus/graph/graph.tsx Просмотреть файл

@ -27,6 +27,7 @@ import {
GetMissingAvatarsCommandType,
GetMoreCommitsCommandType,
SearchCommitsCommandType,
SearchOpenInViewCommandType,
UpdateColumnCommandType,
UpdateSelectedRepositoryCommandType as UpdateRepositorySelectionCommandType,
UpdateSelectionCommandType,
@ -81,6 +82,7 @@ export class GraphApp extends App {
onMoreCommits={(...params) => this.onGetMoreCommits(...params)}
onSearchCommits={(...params) => this.onSearchCommits(...params)}
onSearchCommitsPromise={(...params) => this.onSearchCommitsPromise(...params)}
onSearchOpenInView={(...params) => this.onSearchOpenInView(...params)}
onSelectionChange={debounce(
(selection: { id: string; type: GitGraphRowType }[]) => this.onSelectionChanged(selection),
250,
@ -338,6 +340,10 @@ export class GraphApp extends App {
}
}
private onSearchOpenInView(search: SearchQuery) {
this.sendCommand(SearchOpenInViewCommandType, { search: search });
}
private async onEnsureCommitPromise(id: string, select: boolean) {
try {
return await this.sendCommandWithCompletion(

+ 1
- 0
src/webviews/apps/shared/components/search/react.tsx Просмотреть файл

@ -9,5 +9,6 @@ export const SearchBox = wrap(searchBoxComponent, {
onChange: 'change',
onPrevious: 'previous',
onNext: 'next',
onOpenInView: 'openinview',
},
});

+ 17
- 0
src/webviews/apps/shared/components/search/search-box.ts Просмотреть файл

@ -44,6 +44,18 @@ const template = html`