Add project file picker #3985
Closedjakeleventhal(GitHub profile, opens in a new tab)wants to merge 9 commits into
main fromrefs/pull/3985/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/files/ProjectFilePicker.logic.ts line 49OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -0,0 +29,21 @@29+30+ return null;31+}32+33+export function getProjectFilePickerMatches(34+ entries: ReadonlyArray<ProjectEntry>,35+ rawQuery: string,36+ limit = PROJECT_FILE_PICKER_RESULT_LIMIT,37+): ProjectFilePickerMatch[] {38+ if (limit <= 0) return [];39+40+ const query = rawQuery.toLowerCase().replaceAll(/\s/g, "");41+ const matches: ProjectFilePickerMatch[] = [];42+43+ for (const entry of entries) {44+ if (entry.kind !== "file") continue;45+46+ const name = fileName(entry.path);47+ const nameMatchIndices = findMatchIndices(name, query);48+ const pathMatchIndices = findMatchIndices(entry.path, query);49+ if (nameMatchIndices === null && pathMatchIndices === null) continue;apps/web/src/components/files/ProjectFilePicker.tsx line 170Resolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -0,0 +150,21 @@150+ setHighlightedItemValue(null);151+ setQuery(value);152+ }}153+ value={query}154+ >155+ <CommandInput placeholder="Search files…" />156+ <CommandPanel className="max-h-[min(34rem,76vh)]">157+ <CommandPaletteResults158+ groups={159+ items.length > 0 ? [{ value: "project-files", label: props.projectName, items }] : []160+ }161+ highlightedItemValue={highlightedItemValue}162+ isActionsOnly={false}163+ keybindings={keybindings}164+ onExecuteItem={(item) => {165+ if (item.kind !== "action") return;166+ props.setOpen(false);167+ void item.run();168+ }}169+ emptyStateMessage={emptyStateMessage}170+ />
- apps/web/src/components/CommandPalette.logic.ts lines 37 to 40Resolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -13,0 +20,21 @@20+ readonly mode: "command" | "files";21+ readonly openIntent: CommandPaletteOpenIntent | null;22+}23+24+export type CommandPaletteUiAction =25+ | { readonly _tag: "SetOpen"; readonly open: boolean }26+ | { readonly _tag: "ToggleCommand" }27+ | { readonly _tag: "ToggleFiles" }28+ | { readonly _tag: "OpenAddProject" }29+ | { readonly _tag: "ClearOpenIntent" };30+31+export function reduceCommandPaletteUiState(32+ state: CommandPaletteUiState,33+ action: CommandPaletteUiAction,34+): CommandPaletteUiState {35+ switch (action._tag) {36+ case "SetOpen":37+ return {38+ ...state,39+ open: action.open,40+ openIntent: action.open ? state.openIntent : null,apps/web/src/components/files/projectFilesQueryState.ts lines 152 to 155OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -134,2 +135,21 @@134135 }135136137+export function useProjectFilePickerQuery(138+ environmentId: EnvironmentId,139+ cwd: string,140+ query: string,141+ limit: number,142+) {143+ const listing = useProjectEntriesQuery(environmentId, cwd);144+ const hasQuery = /\S/.test(query);145+ const search = useProjectPathSearch(146+ { environmentId, cwd, query: hasQuery ? query : null },147+ limit,148+ );149+150+ if (hasQuery) {151+ return {152+ entries: search.entries,153+ error: search.error,154+ isPending: search.isPending,155+ matchedQuery: search.searchedQuery,
- apps/web/src/components/files/ProjectFilePicker.logic.ts line 46Resolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -0,0 +26,21 @@26+ indices.push(valueIndex);27+ queryIndex += 1;28+ if (queryIndex === query.length) return indices;29+ }30+31+ return null;32+}33+34+export function getProjectFilePickerMatches(35+ entries: ReadonlyArray<ProjectEntry>,36+ rawQuery: string,37+ limit = PROJECT_FILE_PICKER_RESULT_LIMIT,38+): ProjectFilePickerMatch[] {39+ if (limit <= 0) return [];40+41+ const query = normalizeSearchQuery(rawQuery, {42+ trimLeadingPattern: /^[@./]+/,43+ }).replaceAll(/\s/g, "");44+ const matches: ProjectFilePickerMatch[] = [];45+46+ for (const entry of entries) {
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -35,3 +35,4 @@3535 { key: "mod+-", command: "preview.zoomOut", when: "previewFocus" },3636 { key: "mod+0", command: "preview.resetZoom", when: "previewFocus" },3737 { key: "mod+k", command: "commandPalette.toggle", when: "!terminalFocus" },38+ { key: "mod+p", command: "filePicker.toggle", when: "!terminalFocus" },
- @@ -399,15 +369,14 @@399369 terminalOpen,400370 },401371 });402- if (command !== "commandPalette.toggle") {403- return;404- }372+ if (command !== "commandPalette.toggle" && command !== "filePicker.toggle") return;405373 event.preventDefault();406374 event.stopPropagation();407- toggleOpen();375+ if (command === "filePicker.toggle") toggleFiles();376+ else toggleCommand();408377 };409378 window.addEventListener("keydown", onKeyDown);410379 return () => window.removeEventListener("keydown", onKeyDown);411- }, [keybindings, terminalOpen, toggleOpen]);380+ }, [keybindings, terminalOpen, toggleCommand, toggleFiles]);412381413382 return (
- @@ -418,9 +383,12 @@418- <CommandPaletteDialog419- open={state.open}420- openIntent={state.openIntent}421- setOpen={setOpen}422- clearOpenIntent={clearOpenIntent}423- />424- </CommandDialog>425- </ComposerHandleContext>426- </OpenAddProjectCommandPaletteProvider>383+ <ComposerHandleContext value={composerHandleRef}>384+ <CommandDialog open={state.open} onOpenChange={setOpen}>385+ {children}386+ <CommandPaletteDialog387+ mode={state.mode}388+ open={state.open}389+ openIntent={state.openIntent}390+ setOpen={setOpen}391+ clearOpenIntent={clearOpenIntent}392+ />393+ </CommandDialog>394+ </ComposerHandleContext>
- @@ -409,18 +378,7 @@409378 window.addEventListener("keydown", onKeyDown);410379 return () => window.removeEventListener("keydown", onKeyDown);411- }, [keybindings, terminalOpen, toggleOpen]);380+ }, [keybindings, terminalOpen, toggleCommand, toggleFiles]);412381413382 return (414- <OpenAddProjectCommandPaletteProvider openAddProject={openAddProject}>415- <ComposerHandleContext value={composerHandleRef}>416- <CommandDialog open={state.open} onOpenChange={setOpen}>417- {children}418- <CommandPaletteDialog419- open={state.open}420- openIntent={state.openIntent}421- setOpen={setOpen}422- clearOpenIntent={clearOpenIntent}423- />424- </CommandDialog>425- </ComposerHandleContext>426- </OpenAddProjectCommandPaletteProvider>383+ <ComposerHandleContext value={composerHandleRef}>384+ <CommandDialog open={state.open} onOpenChange={setOpen}>
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
2893e19d-6398-43e5-ad95-1ff1e6b31cbcYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share