From 9080bc7b13b4bfa8b1a0130faf59a47f847e2e31 Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 24 Apr 2026 17:33:12 -0500 Subject: [PATCH] Address remaining Greptile file viewer nits --- ui/src/components/FileViewerSheet.tsx | 19 +------------------ ui/src/components/WorkspaceFileLink.tsx | 2 +- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/ui/src/components/FileViewerSheet.tsx b/ui/src/components/FileViewerSheet.tsx index 6937657d4a1..011bfe06f7c 100644 --- a/ui/src/components/FileViewerSheet.tsx +++ b/ui/src/components/FileViewerSheet.tsx @@ -76,22 +76,6 @@ function formatBytes(size: number | null | undefined): string | null { return `${(size / (1024 * 1024)).toFixed(1)} MB`; } -function decodeBase64ToBytes(data: string): Uint8Array { - const raw = globalThis.atob ? globalThis.atob(data) : ""; - const bytes = new Uint8Array(raw.length); - for (let index = 0; index < raw.length; index += 1) { - bytes[index] = raw.charCodeAt(index); - } - return bytes; -} - -function bytesToDataUrl(bytes: Uint8Array, contentType: string | null | undefined): string { - let binary = ""; - for (const byte of bytes) binary += String.fromCharCode(byte); - const encoded = globalThis.btoa ? globalThis.btoa(binary) : ""; - return `data:${contentType ?? "application/octet-stream"};base64,${encoded}`; -} - function splitContentIntoLines(data: string): string[] { if (data === "") return [""]; const normalized = data.replace(/\r\n?/g, "\n"); @@ -304,9 +288,8 @@ function FileContentViewer({ content, highlightedLine, onLoaded }: FileContentVi }, [highlightedLine]); if (resource.previewKind === "image") { - const encoded = content.content.encoding === "base64" ? content.content.data : content.content.data; const dataUrl = content.content.encoding === "base64" - ? bytesToDataUrl(decodeBase64ToBytes(encoded), resource.contentType) + ? `data:${resource.contentType ?? "application/octet-stream"};base64,${content.content.data}` : null; if (!dataUrl) { return ( diff --git a/ui/src/components/WorkspaceFileLink.tsx b/ui/src/components/WorkspaceFileLink.tsx index 1fd15e52bfe..9adc1db6cfc 100644 --- a/ui/src/components/WorkspaceFileLink.tsx +++ b/ui/src/components/WorkspaceFileLink.tsx @@ -57,8 +57,8 @@ export function WorkspaceFileLink({ return; } if (event.button !== 0) return; - if (!canOpen) return; event.preventDefault(); + if (!canOpen) return; if (onOpen) onOpen(workspaceFileRef); else viewer?.open(workspaceFileRef); };