2025-12-07 19:32:53 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { RiCodeLine, RiFileImageLine, RiFileLine, RiFilePdfLine, RiRefreshLine } from '@remixicon/react';
|
|
|
|
|
import { cn, truncatePathMiddle } from '@/lib/utils';
|
|
|
|
|
import { useFileSearchStore } from '@/stores/useFileSearchStore';
|
2026-02-18 20:08:42 +02:00
|
|
|
import { useConfigStore } from '@/stores/useConfigStore';
|
2026-03-04 01:41:01 +02:00
|
|
|
import { useProjectsStore } from '@/stores/useProjectsStore';
|
|
|
|
|
import { useFilesViewTabsStore } from '@/stores/useFilesViewTabsStore';
|
2025-12-07 19:32:53 +02:00
|
|
|
import { useDebouncedValue } from '@/hooks/useDebouncedValue';
|
2026-03-04 01:41:01 +02:00
|
|
|
import { useChatSearchDirectory } from '@/hooks/useChatSearchDirectory';
|
2025-12-07 19:32:53 +02:00
|
|
|
import type { ProjectFileSearchHit } from '@/lib/opencode/client';
|
|
|
|
|
import { ScrollableOverlay } from '@/components/ui/ScrollableOverlay';
|
2026-01-20 20:20:17 +07:00
|
|
|
import { useDirectoryShowHidden } from '@/lib/directoryShowHidden';
|
|
|
|
|
import { useFilesViewShowGitignored } from '@/lib/filesViewShowGitignored';
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
type FileInfo = ProjectFileSearchHit;
|
2026-02-18 20:08:42 +02:00
|
|
|
type AgentInfo = {
|
|
|
|
|
name: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
mode?: string | null;
|
|
|
|
|
};
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
export interface FileMentionHandle {
|
|
|
|
|
handleKeyDown: (key: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 01:14:10 -08:00
|
|
|
type AutocompleteTab = 'commands' | 'agents' | 'files';
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
interface FileMentionAutocompleteProps {
|
|
|
|
|
searchQuery: string;
|
|
|
|
|
onFileSelect: (file: FileInfo) => void;
|
2026-02-18 20:08:42 +02:00
|
|
|
onAgentSelect?: (agentName: string) => void;
|
2025-12-07 19:32:53 +02:00
|
|
|
onClose: () => void;
|
2026-02-04 01:14:10 -08:00
|
|
|
showTabs?: boolean;
|
|
|
|
|
activeTab?: AutocompleteTab;
|
|
|
|
|
onTabSelect?: (tab: AutocompleteTab) => void;
|
2026-02-23 05:04:25 +07:00
|
|
|
style?: React.CSSProperties;
|
2025-12-07 19:32:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const FileMentionAutocomplete = React.forwardRef<FileMentionHandle, FileMentionAutocompleteProps>(({
|
|
|
|
|
searchQuery,
|
|
|
|
|
onFileSelect,
|
2026-02-18 20:08:42 +02:00
|
|
|
onAgentSelect,
|
2026-02-04 01:14:10 -08:00
|
|
|
onClose,
|
|
|
|
|
showTabs,
|
|
|
|
|
activeTab = 'files',
|
|
|
|
|
onTabSelect,
|
2026-02-23 05:04:25 +07:00
|
|
|
style,
|
2025-12-07 19:32:53 +02:00
|
|
|
}, ref) => {
|
2026-03-04 01:41:01 +02:00
|
|
|
const currentDirectory = useChatSearchDirectory() ?? '';
|
|
|
|
|
const activeProjectId = useProjectsStore((state) => state.activeProjectId);
|
|
|
|
|
const activeProjectPath = useProjectsStore(
|
|
|
|
|
React.useCallback(
|
|
|
|
|
(state) => state.projects.find((project) => project.id === activeProjectId)?.path ?? null,
|
|
|
|
|
[activeProjectId],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
const projectRoot = React.useMemo(() => {
|
|
|
|
|
const candidate = activeProjectPath || currentDirectory;
|
|
|
|
|
return candidate ? candidate.replace(/\\/g, '/').replace(/\/+$/, '') : null;
|
|
|
|
|
}, [activeProjectPath, currentDirectory]);
|
|
|
|
|
const projectTabs = useFilesViewTabsStore(
|
|
|
|
|
React.useCallback(
|
|
|
|
|
(state) => (projectRoot ? state.byRoot[projectRoot] : undefined),
|
|
|
|
|
[projectRoot],
|
|
|
|
|
),
|
|
|
|
|
);
|
2026-04-04 02:19:55 +03:00
|
|
|
const getVisibleAgents = useConfigStore((state) => state.getVisibleAgents);
|
2025-12-07 19:32:53 +02:00
|
|
|
const searchFiles = useFileSearchStore((state) => state.searchFiles);
|
|
|
|
|
const debouncedQuery = useDebouncedValue(searchQuery, 180);
|
2026-01-20 20:20:17 +07:00
|
|
|
const showHidden = useDirectoryShowHidden();
|
|
|
|
|
const showGitignored = useFilesViewShowGitignored();
|
2025-12-07 19:32:53 +02:00
|
|
|
const [files, setFiles] = React.useState<FileInfo[]>([]);
|
2026-02-18 20:08:42 +02:00
|
|
|
const [agents, setAgents] = React.useState<AgentInfo[]>([]);
|
2025-12-07 19:32:53 +02:00
|
|
|
const [loading, setLoading] = React.useState(false);
|
|
|
|
|
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
2025-12-21 01:39:01 +02:00
|
|
|
const [marqueeWidth, setMarqueeWidth] = React.useState(360);
|
|
|
|
|
const [overflowMap, setOverflowMap] = React.useState<Record<number, boolean>>({});
|
|
|
|
|
const [marqueeDurations, setMarqueeDurations] = React.useState<Record<number, number>>({});
|
2025-12-07 19:32:53 +02:00
|
|
|
const itemRefs = React.useRef<(HTMLDivElement | null)[]>([]);
|
2025-12-21 01:39:01 +02:00
|
|
|
const labelRefs = React.useRef<(HTMLSpanElement | null)[]>([]);
|
|
|
|
|
const measureRefs = React.useRef<(HTMLSpanElement | null)[]>([]);
|
2025-12-07 19:32:53 +02:00
|
|
|
const containerRef = React.useRef<HTMLDivElement | null>(null);
|
2026-02-04 01:14:10 -08:00
|
|
|
const ignoreTabClickRef = React.useRef(false);
|
2026-02-18 20:08:42 +02:00
|
|
|
const normalizedSearchQuery = (searchQuery ?? '').trim();
|
|
|
|
|
const visibleAgents = normalizedSearchQuery.length > 0 ? agents : agents.slice(0, 2);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
const recentFiles = React.useMemo(() => {
|
|
|
|
|
if (!projectRoot || !projectTabs) {
|
|
|
|
|
return [] as FileInfo[];
|
2025-12-15 13:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
const ordered = [
|
|
|
|
|
projectTabs.selectedPath,
|
|
|
|
|
...projectTabs.openPaths.slice().reverse(),
|
|
|
|
|
].filter((value): value is string => typeof value === 'string' && value.length > 0);
|
|
|
|
|
|
|
|
|
|
const seen = new Set<string>();
|
|
|
|
|
const queryLower = normalizedSearchQuery.toLowerCase();
|
|
|
|
|
const mapped = ordered
|
|
|
|
|
.filter((filePath) => {
|
|
|
|
|
if (seen.has(filePath)) return false;
|
|
|
|
|
seen.add(filePath);
|
|
|
|
|
const relative = filePath.startsWith(`${projectRoot}/`) ? filePath.slice(projectRoot.length + 1) : filePath;
|
|
|
|
|
if (!queryLower) return true;
|
|
|
|
|
return relative.toLowerCase().includes(queryLower);
|
|
|
|
|
})
|
|
|
|
|
.slice(0, 6)
|
|
|
|
|
.map((filePath) => {
|
|
|
|
|
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
|
|
|
const name = normalizedPath.split('/').filter(Boolean).pop() || normalizedPath;
|
|
|
|
|
const relativePath = normalizedPath.startsWith(`${projectRoot}/`)
|
|
|
|
|
? normalizedPath.slice(projectRoot.length + 1)
|
|
|
|
|
: normalizedPath;
|
|
|
|
|
return {
|
|
|
|
|
name,
|
|
|
|
|
path: normalizedPath,
|
|
|
|
|
relativePath,
|
|
|
|
|
extension: name.includes('.') ? name.split('.').pop()?.toLowerCase() : undefined,
|
|
|
|
|
} satisfies FileInfo;
|
|
|
|
|
});
|
2025-12-15 13:15:45 +02:00
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
return mapped;
|
|
|
|
|
}, [normalizedSearchQuery, projectRoot, projectTabs]);
|
2025-12-15 13:15:45 +02:00
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
const handlePointerDown = (event: MouseEvent | TouchEvent) => {
|
|
|
|
|
const target = event.target as Node | null;
|
|
|
|
|
if (!target || !containerRef.current) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (containerRef.current.contains(target)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
onClose();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener('pointerdown', handlePointerDown, true);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener('pointerdown', handlePointerDown, true);
|
|
|
|
|
};
|
|
|
|
|
}, [onClose]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (!currentDirectory) {
|
|
|
|
|
setFiles([]);
|
2026-03-04 01:41:01 +02:00
|
|
|
setLoading(false);
|
2025-12-07 19:32:53 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-15 13:15:45 +02:00
|
|
|
const normalizedQuery = (debouncedQuery ?? '').trim();
|
2026-01-20 20:20:17 +07:00
|
|
|
const normalizedQueryLower = normalizedQuery
|
|
|
|
|
.replace(/^\.\//, '')
|
|
|
|
|
.replace(/^\/+/, '')
|
|
|
|
|
.toLowerCase();
|
2025-12-15 13:15:45 +02:00
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
if (!normalizedQueryLower) {
|
|
|
|
|
setFiles([]);
|
|
|
|
|
setLoading(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
let cancelled = false;
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
2026-01-20 20:20:17 +07:00
|
|
|
searchFiles(currentDirectory, normalizedQueryLower, 80, {
|
|
|
|
|
includeHidden: showHidden,
|
|
|
|
|
respectGitignore: !showGitignored,
|
2026-03-04 01:41:01 +02:00
|
|
|
type: 'file',
|
2026-01-20 20:20:17 +07:00
|
|
|
})
|
2025-12-07 19:32:53 +02:00
|
|
|
.then((hits) => {
|
|
|
|
|
if (cancelled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-12-15 13:15:45 +02:00
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
const recentSet = new Set(recentFiles.map((file) => file.path));
|
|
|
|
|
setFiles(hits.filter((hit) => !recentSet.has(hit.path)).slice(0, 15));
|
2025-12-07 19:32:53 +02:00
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
if (!cancelled) {
|
|
|
|
|
setFiles([]);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
if (!cancelled) {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true;
|
|
|
|
|
};
|
2026-03-04 01:41:01 +02:00
|
|
|
}, [currentDirectory, debouncedQuery, recentFiles, searchFiles, showHidden, showGitignored]);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-02-18 20:08:42 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
const visibleAgents = getVisibleAgents();
|
|
|
|
|
const normalizedQuery = (searchQuery ?? '').trim().toLowerCase();
|
|
|
|
|
const filtered = visibleAgents
|
|
|
|
|
.filter((agent) => agent.mode && agent.mode !== 'primary')
|
|
|
|
|
.filter((agent) => {
|
|
|
|
|
if (!normalizedQuery) return true;
|
|
|
|
|
const haystack = `${agent.name} ${agent.description ?? ''}`.toLowerCase();
|
|
|
|
|
return haystack.includes(normalizedQuery);
|
|
|
|
|
})
|
|
|
|
|
.map((agent) => ({
|
|
|
|
|
name: agent.name,
|
|
|
|
|
description: agent.description,
|
|
|
|
|
mode: agent.mode,
|
|
|
|
|
}))
|
|
|
|
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
|
|
|
setAgents(filtered);
|
|
|
|
|
}, [getVisibleAgents, searchQuery]);
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
setSelectedIndex(0);
|
2025-12-21 01:39:01 +02:00
|
|
|
setOverflowMap({});
|
|
|
|
|
setMarqueeDurations({});
|
2026-03-04 01:41:01 +02:00
|
|
|
}, [files, recentFiles.length, visibleAgents.length]);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
itemRefs.current[selectedIndex]?.scrollIntoView({
|
|
|
|
|
behavior: 'smooth',
|
|
|
|
|
block: 'nearest'
|
|
|
|
|
});
|
|
|
|
|
}, [selectedIndex]);
|
|
|
|
|
|
2025-12-21 01:39:01 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
let frameId: number | null = null;
|
|
|
|
|
|
|
|
|
|
const updateOverflow = () => {
|
|
|
|
|
if (frameId !== null) {
|
|
|
|
|
cancelAnimationFrame(frameId);
|
|
|
|
|
}
|
|
|
|
|
frameId = requestAnimationFrame(() => {
|
|
|
|
|
const next: Record<number, boolean> = {};
|
|
|
|
|
const durations: Record<number, number> = {};
|
|
|
|
|
labelRefs.current.forEach((node, index) => {
|
|
|
|
|
if (!node) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const measureNode = measureRefs.current[index];
|
|
|
|
|
const fullWidth = measureNode?.offsetWidth ?? node.scrollWidth;
|
|
|
|
|
const overflowPx = Math.max(0, fullWidth - node.clientWidth);
|
|
|
|
|
const isOverflowing = overflowPx > 8;
|
|
|
|
|
next[index] = isOverflowing;
|
|
|
|
|
if (isOverflowing) {
|
|
|
|
|
const duration = Math.max(0.6, overflowPx / 110);
|
|
|
|
|
durations[index] = duration;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
setOverflowMap(next);
|
|
|
|
|
setMarqueeDurations(durations);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateOverflow();
|
|
|
|
|
window.addEventListener('resize', updateOverflow);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
if (frameId !== null) {
|
|
|
|
|
cancelAnimationFrame(frameId);
|
|
|
|
|
}
|
|
|
|
|
window.removeEventListener('resize', updateOverflow);
|
|
|
|
|
};
|
|
|
|
|
}, [files]);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
const labelNode = labelRefs.current[selectedIndex];
|
|
|
|
|
if (!labelNode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const updateWidth = () => {
|
|
|
|
|
const width = labelNode.clientWidth;
|
|
|
|
|
if (width > 0) {
|
|
|
|
|
setMarqueeWidth(width);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateWidth();
|
|
|
|
|
|
|
|
|
|
if (typeof ResizeObserver === 'undefined') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const observer = new ResizeObserver(updateWidth);
|
|
|
|
|
observer.observe(labelNode);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
observer.disconnect();
|
|
|
|
|
};
|
|
|
|
|
}, [selectedIndex]);
|
|
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
const handleFileSelect = React.useCallback((file: FileInfo) => {
|
2025-12-07 19:32:53 +02:00
|
|
|
onFileSelect(file);
|
2026-03-04 01:41:01 +02:00
|
|
|
}, [onFileSelect]);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-02-18 20:08:42 +02:00
|
|
|
const handleAgentPick = React.useCallback((agentName: string) => {
|
|
|
|
|
onAgentSelect?.(agentName);
|
|
|
|
|
}, [onAgentSelect]);
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
React.useImperativeHandle(ref, () => ({
|
|
|
|
|
handleKeyDown: (key: string) => {
|
|
|
|
|
if (key === 'Escape') {
|
|
|
|
|
onClose();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
const total = visibleAgents.length + recentFiles.length + files.length;
|
2025-12-07 19:32:53 +02:00
|
|
|
if (total === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key === 'ArrowDown') {
|
|
|
|
|
setSelectedIndex((prev) => (prev + 1) % total);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key === 'ArrowUp') {
|
|
|
|
|
setSelectedIndex((prev) => (prev - 1 + total) % total);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key === 'Enter' || key === 'Tab') {
|
|
|
|
|
const safeIndex = ((selectedIndex % total) + total) % total;
|
2026-02-18 20:08:42 +02:00
|
|
|
if (safeIndex < visibleAgents.length) {
|
|
|
|
|
const agent = visibleAgents[safeIndex];
|
|
|
|
|
if (agent) {
|
|
|
|
|
handleAgentPick(agent.name);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-04 01:41:01 +02:00
|
|
|
const fileIndex = safeIndex - visibleAgents.length;
|
|
|
|
|
const selectedFile = fileIndex < recentFiles.length
|
|
|
|
|
? recentFiles[fileIndex]
|
|
|
|
|
: files[fileIndex - recentFiles.length];
|
2025-12-07 19:32:53 +02:00
|
|
|
if (selectedFile) {
|
|
|
|
|
handleFileSelect(selectedFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-04 01:41:01 +02:00
|
|
|
}), [files, recentFiles, visibleAgents, selectedIndex, onClose, handleFileSelect, handleAgentPick]);
|
2025-12-07 19:32:53 +02:00
|
|
|
|
|
|
|
|
const getFileIcon = (file: FileInfo) => {
|
|
|
|
|
const ext = file.extension?.toLowerCase();
|
|
|
|
|
switch (ext) {
|
|
|
|
|
case 'ts':
|
|
|
|
|
case 'tsx':
|
|
|
|
|
case 'js':
|
|
|
|
|
case 'jsx':
|
2026-02-01 18:29:34 +02:00
|
|
|
return <RiCodeLine className="h-3.5 w-3.5 text-[var(--status-info)]" />;
|
2025-12-07 19:32:53 +02:00
|
|
|
case 'json':
|
2026-02-01 18:29:34 +02:00
|
|
|
return <RiCodeLine className="h-3.5 w-3.5 text-[var(--status-warning)]" />;
|
2025-12-07 19:32:53 +02:00
|
|
|
case 'md':
|
|
|
|
|
case 'mdx':
|
2026-02-01 18:29:34 +02:00
|
|
|
return <RiFileLine className="h-3.5 w-3.5 text-muted-foreground" />;
|
2025-12-07 19:32:53 +02:00
|
|
|
case 'png':
|
|
|
|
|
case 'jpg':
|
|
|
|
|
case 'jpeg':
|
|
|
|
|
case 'gif':
|
|
|
|
|
case 'svg':
|
2026-02-01 18:29:34 +02:00
|
|
|
return <RiFileImageLine className="h-3.5 w-3.5 text-[var(--status-success)]" />;
|
2025-12-07 19:32:53 +02:00
|
|
|
default:
|
|
|
|
|
return <RiFilePdfLine className="h-3.5 w-3.5 text-muted-foreground" />;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
ref={containerRef}
|
2026-02-26 17:21:32 +08:00
|
|
|
className="absolute z-[100] min-w-0 w-full max-w-[640px] max-h-64 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col"
|
2026-02-23 05:04:25 +07:00
|
|
|
style={style}
|
2025-12-07 19:32:53 +02:00
|
|
|
>
|
2026-02-04 01:14:10 -08:00
|
|
|
{showTabs ? (
|
|
|
|
|
<div className="px-2 pt-2 pb-1 border-b border-border/60">
|
|
|
|
|
<div className="flex items-center gap-1 rounded-lg bg-[var(--surface-elevated)] p-1">
|
|
|
|
|
{([
|
|
|
|
|
{ id: 'commands' as const, label: 'Commands' },
|
|
|
|
|
{ id: 'agents' as const, label: 'Agents' },
|
|
|
|
|
{ id: 'files' as const, label: 'Files' },
|
|
|
|
|
]).map((tab) => (
|
|
|
|
|
<button
|
|
|
|
|
key={tab.id}
|
|
|
|
|
type="button"
|
|
|
|
|
className={cn(
|
|
|
|
|
'flex-1 px-2.5 py-1 rounded-md typography-meta font-semibold transition-none',
|
|
|
|
|
activeTab === tab.id
|
2026-02-25 14:32:23 +02:00
|
|
|
? 'bg-interactive-selection text-interactive-selection-foreground shadow-none'
|
2026-02-04 01:14:10 -08:00
|
|
|
: 'text-muted-foreground hover:bg-interactive-hover/50'
|
|
|
|
|
)}
|
|
|
|
|
onPointerDown={(event) => {
|
|
|
|
|
if (event.pointerType !== 'touch') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
ignoreTabClickRef.current = true;
|
|
|
|
|
onTabSelect?.(tab.id);
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (ignoreTabClickRef.current) {
|
|
|
|
|
ignoreTabClickRef.current = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
onTabSelect?.(tab.id);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{tab.label}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
2025-12-07 19:32:53 +02:00
|
|
|
<ScrollableOverlay outerClassName="flex-1 min-h-0" className="px-0">
|
|
|
|
|
{loading ? (
|
|
|
|
|
<div className="flex items-center justify-center py-4">
|
|
|
|
|
<RiRefreshLine className="h-4 w-4 animate-spin text-muted-foreground" />
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="pb-2">
|
2026-02-18 20:08:42 +02:00
|
|
|
{visibleAgents.map((agent, index) => {
|
|
|
|
|
const isSelected = selectedIndex === index;
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={`agent-${agent.name}`}
|
|
|
|
|
ref={(el) => { itemRefs.current[index] = el; }}
|
|
|
|
|
className={cn(
|
|
|
|
|
'flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg',
|
|
|
|
|
isSelected && 'bg-interactive-selection',
|
|
|
|
|
)}
|
|
|
|
|
onClick={() => handleAgentPick(agent.name)}
|
|
|
|
|
onMouseEnter={() => setSelectedIndex(index)}
|
|
|
|
|
>
|
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
<div className="font-semibold truncate">@{agent.name}</div>
|
|
|
|
|
{agent.description ? (
|
|
|
|
|
<div className="typography-meta text-muted-foreground truncate">{agent.description}</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2026-03-04 01:41:01 +02:00
|
|
|
{visibleAgents.length === 2 && normalizedSearchQuery.length === 0 && agents.length > 2 && (
|
|
|
|
|
<div className="px-3 py-1 typography-meta text-muted-foreground">
|
|
|
|
|
Type to search more agents
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{visibleAgents.length > 0 && (recentFiles.length > 0 || files.length > 0) && (
|
2026-02-18 20:08:42 +02:00
|
|
|
<div className="my-1 border-t border-border/60" />
|
|
|
|
|
)}
|
2026-03-04 01:41:01 +02:00
|
|
|
{recentFiles.map((file, index) => {
|
2026-02-18 20:08:42 +02:00
|
|
|
const rowIndex = visibleAgents.length + index;
|
2025-12-07 19:32:53 +02:00
|
|
|
const relativePath = file.relativePath || file.name;
|
2026-02-26 17:21:32 +08:00
|
|
|
const displayPath = truncatePathMiddle(relativePath, { maxLength: 60 });
|
2026-02-18 20:08:42 +02:00
|
|
|
const isSelected = selectedIndex === rowIndex;
|
|
|
|
|
const isOverflowing = overflowMap[rowIndex] ?? false;
|
|
|
|
|
const marqueeDuration = marqueeDurations[rowIndex] ?? 2.6;
|
2025-12-07 19:32:53 +02:00
|
|
|
|
2026-03-04 01:41:01 +02:00
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={`recent-${file.path}`}
|
|
|
|
|
ref={(el) => { itemRefs.current[rowIndex] = el; }}
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg",
|
|
|
|
|
isSelected && "bg-interactive-selection"
|
|
|
|
|
)}
|
|
|
|
|
onClick={() => handleFileSelect(file)}
|
|
|
|
|
onMouseEnter={() => setSelectedIndex(rowIndex)}
|
|
|
|
|
>
|
|
|
|
|
{getFileIcon(file)}
|
|
|
|
|
<span
|
|
|
|
|
ref={(el) => { labelRefs.current[rowIndex] = el; }}
|
|
|
|
|
className="relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container"
|
|
|
|
|
style={isSelected ? {
|
|
|
|
|
['--file-mention-marquee-width' as string]: `${marqueeWidth}px`,
|
|
|
|
|
['--file-mention-marquee-duration' as string]: `${marqueeDuration}s`
|
|
|
|
|
} : undefined}
|
|
|
|
|
aria-label={relativePath}
|
|
|
|
|
>
|
|
|
|
|
<span
|
|
|
|
|
ref={(el) => { measureRefs.current[rowIndex] = el; }}
|
|
|
|
|
className="absolute invisible whitespace-nowrap pointer-events-none"
|
|
|
|
|
aria-hidden
|
|
|
|
|
>
|
|
|
|
|
{relativePath}
|
|
|
|
|
</span>
|
|
|
|
|
{isOverflowing && isSelected ? (
|
|
|
|
|
<span className="inline-block whitespace-nowrap file-mention-marquee">
|
|
|
|
|
{relativePath}
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="block truncate">
|
|
|
|
|
{displayPath}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
{recentFiles.length > 0 && files.length > 0 && (
|
|
|
|
|
<div className="my-1 border-t border-border/60" />
|
|
|
|
|
)}
|
|
|
|
|
{files.map((file, index) => {
|
|
|
|
|
const rowIndex = visibleAgents.length + recentFiles.length + index;
|
|
|
|
|
const relativePath = file.relativePath || file.name;
|
|
|
|
|
const displayPath = truncatePathMiddle(relativePath, { maxLength: 60 });
|
|
|
|
|
const isSelected = selectedIndex === rowIndex;
|
|
|
|
|
const isOverflowing = overflowMap[rowIndex] ?? false;
|
|
|
|
|
const marqueeDuration = marqueeDurations[rowIndex] ?? 2.6;
|
|
|
|
|
|
2025-12-07 19:32:53 +02:00
|
|
|
const item = (
|
|
|
|
|
<div
|
2026-02-18 20:08:42 +02:00
|
|
|
ref={(el) => { itemRefs.current[rowIndex] = el; }}
|
2026-02-01 18:29:34 +02:00
|
|
|
className={cn(
|
|
|
|
|
"flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg",
|
|
|
|
|
isSelected && "bg-interactive-selection"
|
|
|
|
|
)}
|
2025-12-07 19:32:53 +02:00
|
|
|
onClick={() => handleFileSelect(file)}
|
2026-02-18 20:08:42 +02:00
|
|
|
onMouseEnter={() => setSelectedIndex(rowIndex)}
|
2025-12-07 19:32:53 +02:00
|
|
|
>
|
|
|
|
|
{getFileIcon(file)}
|
2025-12-21 01:39:01 +02:00
|
|
|
<span
|
2026-02-18 20:08:42 +02:00
|
|
|
ref={(el) => { labelRefs.current[rowIndex] = el; }}
|
2025-12-26 02:39:56 +02:00
|
|
|
className="relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container"
|
2025-12-21 01:39:01 +02:00
|
|
|
style={isSelected ? {
|
|
|
|
|
['--file-mention-marquee-width' as string]: `${marqueeWidth}px`,
|
|
|
|
|
['--file-mention-marquee-duration' as string]: `${marqueeDuration}s`
|
|
|
|
|
} : undefined}
|
|
|
|
|
aria-label={relativePath}
|
|
|
|
|
>
|
|
|
|
|
<span
|
2026-02-18 20:08:42 +02:00
|
|
|
ref={(el) => { measureRefs.current[rowIndex] = el; }}
|
2025-12-21 01:39:01 +02:00
|
|
|
className="absolute invisible whitespace-nowrap pointer-events-none"
|
|
|
|
|
aria-hidden
|
|
|
|
|
>
|
|
|
|
|
{relativePath}
|
|
|
|
|
</span>
|
|
|
|
|
{isOverflowing && isSelected ? (
|
|
|
|
|
<span className="inline-block whitespace-nowrap file-mention-marquee">
|
|
|
|
|
{relativePath}
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="block truncate">
|
|
|
|
|
{displayPath}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2025-12-07 19:32:53 +02:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
2025-12-21 01:39:01 +02:00
|
|
|
<React.Fragment key={file.path}>
|
|
|
|
|
{item}
|
|
|
|
|
</React.Fragment>
|
2025-12-07 19:32:53 +02:00
|
|
|
);
|
|
|
|
|
})}
|
2026-03-04 01:41:01 +02:00
|
|
|
{files.length === 0 && recentFiles.length === 0 && visibleAgents.length === 0 && (
|
2025-12-07 19:32:53 +02:00
|
|
|
<div className="px-3 py-2 typography-ui-label text-muted-foreground">
|
2026-02-18 20:08:42 +02:00
|
|
|
No matches found
|
2025-12-07 19:32:53 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</ScrollableOverlay>
|
|
|
|
|
<div className="px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground">
|
|
|
|
|
↑↓ navigate • Enter select • Esc close
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
});
|