2 import { Folder } from '@lucide/svelte';
3 import { cn } from '$lib/components/ui/utils';
4 import { highlightMatch } from '$lib/utils';
5 import { fly } from 'svelte/transition';
7 // Fly-in transition for the results list.
9 const FLY_DURATION_MS = 100;
17 container?: HTMLDivElement | null;
18 onCommit?: (path: string) => void;
19 onHover?: (index: number) => void;
23 container = $bindable(null),
36 class="max-h-48 overflow-y-auto py-2"
37 transition:fly={{ duration: FLY_DURATION_MS, y: FLY_Y_PX }}
39 {#if isSearching && results.length === 0}
40 <div class="px-2 py-1.5 text-sm text-muted-foreground">Searching...</div>
42 <div class="px-2 py-1.5 text-sm text-destructive">{error}</div>
43 {:else if results.length === 0}
44 <div class="px-2 py-1.5 text-sm text-muted-foreground">No matching folders</div>
46 {#each results as path, index (path)}
49 data-result-index={index}
50 data-highlighted={index === hoveredIndex ? '' : undefined}
52 'relative flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground'
54 onclick={() => onCommit?.(path)}
55 onmouseenter={() => onHover?.(index)}
57 <Folder class="size-4 shrink-0 text-muted-foreground" />
58 <span class="min-w-0 flex-1 truncate font-mono text-left">
59 {#each highlightMatch(path, rawQuery.trim()) as seg, segIndex (segIndex)}
61 <mark class="rounded bg-yellow-200/60 px-0.5 text-foreground dark:bg-yellow-500/30"