diff --git a/apps/desktop/src/components/workspace/editor/latex-editor.tsx b/apps/desktop/src/components/workspace/editor/latex-editor.tsx
index 27235ff..e3f8f29 100644
--- a/apps/desktop/src/components/workspace/editor/latex-editor.tsx
+++ b/apps/desktop/src/components/workspace/editor/latex-editor.tsx
@@ -28,7 +28,7 @@ import {
import { unifiedMergeView, getChunks, acceptChunk, rejectChunk } from "@codemirror/merge";
import { latex, latexLinter } from "codemirror-lang-latex";
import { linter, lintGutter, forEachDiagnostic, type Diagnostic } from "@codemirror/lint";
-import { useDocumentStore } from "@/stores/document-store";
+import { useDocumentStore, type ProjectFile } from "@/stores/document-store";
import { useProposedChangesStore, type ProposedChange } from "@/stores/proposed-changes-store";
import { useClaudeChatStore } from "@/stores/claude-chat-store";
import { useHistoryStore } from "@/stores/history-store";
@@ -41,6 +41,8 @@ import { ProposedChangesPanel } from "@/components/claude-chat/proposed-changes-
import { ImagePreview } from "./image-preview";
import { SearchPanel } from "./search-panel";
import { ProblemsPanel, type DiagnosticItem } from "./problems-panel";
+import { PdfViewer } from "@/components/workspace/preview/pdf-viewer";
+import { readFile } from "@tauri-apps/plugin-fs";
function getActiveFileContent(): string {
const state = useDocumentStore.getState();
@@ -70,7 +72,7 @@ export function LatexEditor() {
const isTextFile = activeFile?.type === "tex" || activeFile?.type === "bib" || activeFile?.type === "style" || activeFile?.type === "other";
const activeFileContent = activeFile?.content;
- const [imageScale, setImageScale] = useState(0.5);
+ const [imageScale, setImageScale] = useState(1.0);
const [isSearchOpen, setIsSearchOpen] = useState(false);
const [searchQuery, setSearchQuery] = useState("");
const [matchCount, setMatchCount] = useState(0);
@@ -598,25 +600,7 @@ export function LatexEditor() {
}, []);
if (activeFile?.type === "pdf") {
- return (
-
-
-
- {activeFile.dataUrl ? (
-
- ) : (
-
- Unable to load PDF
-
- )}
-
-
-
- );
+ return ;
}
if (!isTextFile && activeFile) {
@@ -739,3 +723,61 @@ export function LatexEditor() {
);
}
+
+// ─── Inline PDF Viewer (for PDF files opened from file tree) ───
+
+function InlinePdfViewer({
+ file,
+ editorView,
+ imageScale,
+ onImageScaleChange,
+}: {
+ file: ProjectFile;
+ editorView: React.RefObject;
+ imageScale: number;
+ onImageScaleChange: (scale: number) => void;
+}) {
+ const [pdfData, setPdfData] = useState(null);
+ const [error, setError] = useState(null);
+
+ useEffect(() => {
+ let cancelled = false;
+ setPdfData(null);
+ setError(null);
+
+ readFile(file.absolutePath)
+ .then((data) => {
+ if (!cancelled) setPdfData(new Uint8Array(data));
+ })
+ .catch((err) => {
+ if (!cancelled) setError(String(err));
+ });
+
+ return () => { cancelled = true; };
+ }, [file.absolutePath]);
+
+ return (
+
+
+
+ {pdfData ? (
+
setError(msg)}
+ />
+ ) : error ? (
+
+ Failed to load PDF: {error}
+
+ ) : (
+
+ Loading PDF...
+
+ )}
+
+
+
+ );
+}
diff --git a/apps/desktop/src/components/workspace/preview/pdf-viewer.tsx b/apps/desktop/src/components/workspace/preview/pdf-viewer.tsx
index 59c7fce..32ddb44 100644
--- a/apps/desktop/src/components/workspace/preview/pdf-viewer.tsx
+++ b/apps/desktop/src/components/workspace/preview/pdf-viewer.tsx
@@ -136,16 +136,11 @@ export function PdfViewer({
);
const handlePageLoadSuccess = useCallback(
- ({ width }: { width: number }) => {
- if (hasSetInitialScale.current) return;
- if (containerRef.current && onScaleChange) {
- hasSetInitialScale.current = true;
- const containerWidth = containerRef.current.clientWidth - 32;
- const fitScale = containerWidth / width;
- onScaleChange(Math.min(fitScale, 2));
- }
+ ({ width: _width }: { width: number }) => {
+ // Scale is now managed externally — default 100% (1.0)
+ hasSetInitialScale.current = true;
},
- [onScaleChange],
+ [],
);
const handleLoadError = useCallback(
@@ -341,7 +336,7 @@ export function PdfViewer({
}, []);
return (
-