#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
fix(text-editor): open a workbench file at the viewer's zoom, not 150% (#8311)
ConnorYoh0e4a3b28c9b3
diff --git a/frontend/editor/src/core/tests/stubbed/pdf-text-editor-entry-zoom.spec.ts b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-entry-zoom.spec.tsnew file mode 100644index 0000000000..75885744f3--- /dev/null+++ b/frontend/editor/src/core/tests/stubbed/pdf-text-editor-entry-zoom.spec.ts@@ -0,0 +1,32 @@+import path from "path";+import { test, expect } from "@app/tests/helpers/stub-test-base";++const FIXTURES = path.join(import.meta.dirname, "../test-fixtures");+const MULTIPAGE_PDF = path.join(FIXTURES, "annotations_out_of_order.pdf");++test("the text editor opens a workbench file at the viewer's zoom", async ({+ page,+}) => {+ await page.goto("/editor");+ await page.locator('input[type="file"]').first().setInputFiles(MULTIPAGE_PDF);+ await expect(page.locator('[data-page-index="0"]').first()).toBeVisible({+ timeout: 30_000,+ });+ const readout = page.getByText(/%$/).first();+ const initialZoom = await readout.textContent();+ await page.getByRole("button", { name: "Zoom In" }).first().click();+ await expect(readout).not.toHaveText(initialZoom ?? "");+ const viewerZoom = await readout.textContent();++ await page+ .getByRole("link", { name: "PDF Text Editor", exact: true })+ .first()+ .click();+ await expect(page.getByTestId("pdf-editor-page-0")).toBeVisible({+ timeout: 30_000,+ });++ await expect(page.getByTestId("pdf-editor-zoom-percent")).toHaveText(+ viewerZoom ?? "",+ );+});diff --git a/frontend/editor/src/core/tools/pdfTextEditor/PdfTextEditor.tsx b/frontend/editor/src/core/tools/pdfTextEditor/PdfTextEditor.tsxindex d983341fca..79b864087d 100644--- a/frontend/editor/src/core/tools/pdfTextEditor/PdfTextEditor.tsx+++ b/frontend/editor/src/core/tools/pdfTextEditor/PdfTextEditor.tsx@@ -8,6 +8,7 @@ import { useTranslation } from "react-i18next";import { Icon } from "@app/ui/Icon";import { downloadFile } from "@app/services/downloadService";import { useFileContext, useFileSelection } from "@app/contexts/FileContext";+import { useViewer } from "@app/contexts/ViewerContext";import { createStirlingFilesAndStubs } from "@app/services/fileStubHelpers";import type { FileId } from "@app/types/file";import type { BaseToolProps } from "@app/types/tool";@@ -41,6 +42,7 @@ import { jpegExifOrientation } from "@app/tools/pdfTextEditor/util/jpegOrientatiimport { MergeRunsCommand } from "@app/tools/pdfTextEditor/commands/MergeRunsCommand";import { UngroupParagraphCommand } from "@app/tools/pdfTextEditor/commands/UngroupParagraphCommand";import { exportToBlob } from "@app/tools/pdfTextEditor/util/exportPdf";+import { clampRenderScale } from "@app/tools/pdfTextEditor/util/fitToWidth";import {detectSaveRisks,hasSaveRisks,@@ -63,6 +65,9 @@ export default function PdfTextEditor(_props: BaseToolProps) {const isMobile = useIsMobile();const { store, state } = useEditorStore();const load = useDocumentLoader(store);+ const { getZoomState } = useViewer();+ const viewerZoomRef = useRef(getZoomState);+ viewerZoomRef.current = getZoomState;const [selection, setSelection] = useState<SelectionState>(store.selection.value,@@ -99,9 +104,16 @@ export default function PdfTextEditor(_props: BaseToolProps) {(name: string, fileId?: FileId) => {setOpenedFileName(name);setSourceFile(fileId ?? null);+ // A workbench file opens at the zoom the viewer showed it at. The+ // viewer's fallback state carries no level, so a viewer that never+ // opened a document leaves the editor's own default alone.+ const viewerZoom = viewerZoomRef.current();+ if (fileId && viewerZoom.level !== undefined) {+ store.setRenderScale(clampRenderScale(viewerZoom.currentZoom));+ }pinWorkbench();},- [pinWorkbench, setSourceFile],+ [pinWorkbench, setSourceFile, store],);const { openFile: openWorkbenchFile, adopt: adoptFile } = useAutoLoadFile(load,