Skip to content

Commit 8747464

Browse files
7418claude
andcommitted
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>
1 parent 57ba6b2 commit 8747464

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/components/layout/AppShell.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ export function AppShell({ children }: { children: React.ReactNode }) {
115115
}, []);
116116

117117
// Auto-open panel on chat detail routes, close on others
118+
// Also close doc preview when navigating away or switching sessions
118119
useEffect(() => {
119120
setPanelOpenRaw(isChatDetailRoute);
120-
if (!isChatDetailRoute) {
121-
setPreviewFileRaw(null);
122-
}
123-
}, [isChatDetailRoute]);
121+
setPreviewFileRaw(null);
122+
}, [isChatDetailRoute, pathname]);
124123

125124
const setPanelOpen = useCallback((open: boolean) => {
126125
setPanelOpenRaw(open);

src/components/layout/DocPreview.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ export function DocPreview({
9393
};
9494
}, [filePath]);
9595

96-
const handleCopyPath = async () => {
97-
await navigator.clipboard.writeText(filePath);
96+
const handleCopyContent = async () => {
97+
const text = preview?.content || filePath;
98+
await navigator.clipboard.writeText(text);
9899
setCopied(true);
99100
setTimeout(() => setCopied(false), 2000);
100101
};
@@ -126,13 +127,13 @@ export function DocPreview({
126127
<ViewModeToggle value={viewMode} onChange={onViewModeChange} />
127128
)}
128129

129-
<Button variant="ghost" size="icon-sm" onClick={handleCopyPath}>
130+
<Button variant="ghost" size="icon-sm" onClick={handleCopyContent}>
130131
{copied ? (
131132
<HugeiconsIcon icon={Tick01Icon} className="h-3.5 w-3.5 text-green-500" />
132133
) : (
133134
<HugeiconsIcon icon={Copy01Icon} className="h-3.5 w-3.5" />
134135
)}
135-
<span className="sr-only">Copy path</span>
136+
<span className="sr-only">Copy content</span>
136137
</Button>
137138

138139
<Button variant="ghost" size="icon-sm" onClick={onClose}>

src/components/layout/RightPanel.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ export function RightPanel({ width }: RightPanelProps) {
6767
}, [handleSaveName]);
6868

6969
const handleFileSelect = useCallback((path: string) => {
70+
// Only open preview for text-based files, skip images/videos/binaries
71+
const ext = path.split(".").pop()?.toLowerCase() || "";
72+
const NON_PREVIEWABLE = new Set([
73+
"png", "jpg", "jpeg", "gif", "bmp", "ico", "webp", "svg", "avif",
74+
"mp4", "mov", "avi", "mkv", "webm", "flv", "wmv",
75+
"mp3", "wav", "ogg", "flac", "aac", "wma",
76+
"zip", "tar", "gz", "rar", "7z", "bz2",
77+
"pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx",
78+
"exe", "dll", "so", "dylib", "bin", "dmg", "iso",
79+
"woff", "woff2", "ttf", "otf", "eot",
80+
]);
81+
if (NON_PREVIEWABLE.has(ext)) return;
82+
7083
// Toggle: clicking the same file closes the preview
7184
if (previewFile === path) {
7285
setPreviewFile(null);

0 commit comments

Comments
 (0)