MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / GlobalSearchDialog

Function GlobalSearchDialog

src/components/GlobalSearchDialog.tsx:39–263  ·  view source on GitHub ↗
({ onDone, onInsert }: Props)

Source from the content-addressed store, hash-verified

37 * Debounced ripgrep search across the workspace.
38 */
39export function GlobalSearchDialog({ onDone, onInsert }: Props): React.ReactNode {
40 useRegisterOverlay('global-search');
41 const { columns, rows } = useTerminalSize();
42 const previewOnRight = columns >= 140;
43 // Chrome (title + search + matchLabel + hints + pane border + gaps) eats
44 // ~14 rows. Shrink the list on short terminals so the dialog doesn't clip.
45 const visibleResults = Math.min(VISIBLE_RESULTS, Math.max(4, rows - 14));
46
47 const [matches, setMatches] = useState<Match[]>([]);
48 const [truncated, setTruncated] = useState(false);
49 const [isSearching, setIsSearching] = useState(false);
50 const [query, setQuery] = useState('');
51 const [focused, setFocused] = useState<Match | undefined>(undefined);
52 const [preview, setPreview] = useState<{
53 file: string;
54 line: number;
55 content: string;
56 } | null>(null);
57 const abortRef = useRef<AbortController | null>(null);
58 const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
59
60 useEffect(() => {
61 return () => {
62 if (timeoutRef.current) clearTimeout(timeoutRef.current);
63 abortRef.current?.abort();
64 };
65 }, []);
66
67 // Load context lines around the focused match. AbortController prevents
68 // holding ↓ from piling up reads.
69 useEffect(() => {
70 if (!focused) {
71 setPreview(null);
72 return;
73 }
74 const controller = new AbortController();
75 const absolute = resolvePath(getCwd(), focused.file);
76 const start = Math.max(0, focused.line - PREVIEW_CONTEXT_LINES - 1);
77 void readFileInRange(absolute, start, PREVIEW_CONTEXT_LINES * 2 + 1, undefined, controller.signal)
78 .then(r => {
79 if (controller.signal.aborted) return;
80 setPreview({
81 file: focused.file,
82 line: focused.line,
83 content: r.content,
84 });
85 })
86 .catch(() => {
87 if (controller.signal.aborted) return;
88 setPreview({
89 file: focused.file,
90 line: focused.line,
91 content: '(preview unavailable)',
92 });
93 });
94 return () => controller.abort();
95 }, [focused]);
96

Callers

nothing calls this directly

Calls 10

useRegisterOverlayFunction · 0.85
useTerminalSizeFunction · 0.85
getCwdFunction · 0.85
readFileInRangeFunction · 0.85
truncatePathMiddleFunction · 0.85
highlightMatchFunction · 0.85
truncateToWidthFunction · 0.85
maxMethod · 0.80
handleInsertFunction · 0.70
abortMethod · 0.65

Tested by

no test coverage detected