fix: doc preview bugs — close on chat switch, copy content, filter binary files

- Close doc preview when switching between chats (pathname change)
- Copy button now copies file content instead of file path
- Skip preview for images, videos, audio, archives, and other binary files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
7418andClaude Opus 4.6 committed 2026-02-11 23:26:29 +08:00
1 parent 57ba6b2584
commit 8747464c2f
3 files changed
+21 -8

No files matched your search

+3 -4
View File
@@ -115,12 +115,11 @@ export function AppShell({ children }: { children: React.ReactNode }) {
}, []);
// Auto-open panel on chat detail routes, close on others
// Also close doc preview when navigating away or switching sessions
useEffect(() => {
setPanelOpenRaw(isChatDetailRoute);
if (!isChatDetailRoute) {
setPreviewFileRaw(null);
}
}, [isChatDetailRoute]);
setPreviewFileRaw(null);
}, [isChatDetailRoute, pathname]);
const setPanelOpen = useCallback((open: boolean) => {
setPanelOpenRaw(open);
+5 -4
View File
@@ -93,8 +93,9 @@ export function DocPreview({
};
}, [filePath]);
const handleCopyPath = async () => {
await navigator.clipboard.writeText(filePath);
const handleCopyContent = async () => {
const text = preview?.content || filePath;
await navigator.clipboard.writeText(text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
@@ -126,13 +127,13 @@ export function DocPreview({
<ViewModeToggle value={viewMode} onChange={onViewModeChange} />
)}
<Button variant="ghost" size="icon-sm" onClick={handleCopyPath}>
<Button variant="ghost" size="icon-sm" onClick={handleCopyContent}>
{copied ? (
<HugeiconsIcon icon={Tick01Icon} className="h-3.5 w-3.5 text-green-500" />
) : (
<HugeiconsIcon icon={Copy01Icon} className="h-3.5 w-3.5" />
)}
<span className="sr-only">Copy path</span>
<span className="sr-only">Copy content</span>
</Button>
<Button variant="ghost" size="icon-sm" onClick={onClose}>
+13
View File
@@ -67,6 +67,19 @@ export function RightPanel({ width }: RightPanelProps) {
}, [handleSaveName]);
const handleFileSelect = useCallback((path: string) => {
// Only open preview for text-based files, skip images/videos/binaries
const ext = path.split(".").pop()?.toLowerCase() || "";
const NON_PREVIEWABLE = new Set([
"png", "jpg", "jpeg", "gif", "bmp", "ico", "webp", "svg", "avif",
"mp4", "mov", "avi", "mkv", "webm", "flv", "wmv",
"mp3", "wav", "ogg", "flac", "aac", "wma",
"zip", "tar", "gz", "rar", "7z", "bz2",
"pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx",
"exe", "dll", "so", "dylib", "bin", "dmg", "iso",
"woff", "woff2", "ttf", "otf", "eot",
]);
if (NON_PREVIEWABLE.has(ext)) return;
// Toggle: clicking the same file closes the preview
if (previewFile === path) {
setPreviewFile(null);