Skip to content

fix(editor): preserve PDF zoom when file content reloads - #10168

Merged
AmethystLiang merged 2 commits into
stablyai:mainfrom
innocarpe:fix/pdf-preserve-zoom-on-reload
Jul 23, 2026
Merged

AmethystLiang merged 2 commits into
stablyai:mainfrom
innocarpe:fix/pdf-preserve-zoom-on-reload

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

Summary

  • Opening/updating a PDF always rebuilt the pdf.js viewer and forced currentScaleValue = 'page-width', so any user zoom was lost after an on-disk update.
  • Track a per-file scale preference (fit-to-width vs absolute) across content reloads; reset only when the open file path changes.
  • Toolbar / shortcut zoom in·out·reset update the same preference so the next reload restores it.

Fixes #10165

Test plan

  • Unit: pdf-scale-preference apply / step / clamp
  • Manual: open a PDF → zoom in → save/overwrite the file externally → preview reloads at the same zoom
  • Manual: fit-to-width then reload → stays fit-to-width
  • Manual: switch to a different PDF path → zoom resets to fit-to-width

PdfViewer rebuilt the pdf.js document on every content change and always
reset to page-width, so external PDF updates wiped the user's zoom. Keep
a fit-width vs absolute preference across reloads for the same file path.

Closes stablyai#10165
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ba4cdb0-0970-42ab-a535-880848e3a198

📥 Commits

Reviewing files that changed from the base of the PR and between a1ce5ed and 73b9414.

📒 Files selected for processing (1)
  • src/renderer/src/components/editor/PdfViewer.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/editor/PdfViewer.tsx

📝 Walkthrough

Walkthrough

PDF zoom management now uses shared helpers for clamping, applying, and stepping scale preferences. PdfViewer preserves zoom preferences across reloads for the same file, resets them when the file changes, restores them after loading, and uses the same logic for keyboard and toolbar controls. Tests cover numeric bounds, fit-to-width behavior, and zoom stepping.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes Summary and Testing, but it omits Screenshots, AI Review Report, Security Audit, and Notes from the template. Add the missing template sections and complete the testing checklist, including screenshots or a clear no-visual-change note.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preserving PDF zoom across reloads in the editor.
Linked Issues check ✅ Passed The changes address #10165 by retaining per-file PDF zoom preference across content reloads and resetting it on file path changes.
Out of Scope Changes check ✅ Passed The helper module, tests, and viewer refactor all support the PDF zoom persistence fix and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 55969d4b-2d59-4d24-9329-faf4053ef1f5

📥 Commits

Reviewing files that changed from the base of the PR and between 8a23618 and a1ce5ed.

📒 Files selected for processing (3)
  • src/renderer/src/components/editor/PdfViewer.tsx
  • src/renderer/src/components/editor/pdf-scale-preference.test.ts
  • src/renderer/src/components/editor/pdf-scale-preference.ts

@AmethystLiang
AmethystLiang self-requested a review July 23, 2026 18:57
Collapse six copies of the step-scale-and-record-preference logic (three
directions duplicated across the keyboard handler and toolbar callbacks)
into a single stepZoom callback; the keydown handler now reuses zoomIn/
zoomOut/zoomReset so keyboard and toolbar can't drift apart.

Co-authored-by: Orca <[email protected]>

@AmethystLiang AmethystLiang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the PDF zoom-preservation logic in depth, including tracing pdf.js viewer internals (#setScale early-returns for preset strings on empty _pages, but numeric scales apply directly and survive async page init — so the numeric restore path is sound and the default page-width path is byte-identical to prior behavior). No performance regression: the scale logic is O(1) and the pre-existing per-reload viewer rebuild is untouched.

Also folded in a small refactor deduping the six copies of the step-scale-and-record-preference logic into a shared stepZoom callback, with the keyboard handler reusing zoomIn/zoomOut/zoomReset. Lint, typecheck, and unit tests are green.

@AmethystLiang
AmethystLiang merged commit a34eb87 into stablyai:main Jul 23, 2026
1 check passed
@Jhnnn001 Jhnnn001 mentioned this pull request Jul 24, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* fix(editor): preserve PDF zoom when file content reloads

PdfViewer rebuilt the pdf.js document on every content change and always
reset to page-width, so external PDF updates wiped the user's zoom. Keep
a fit-width vs absolute preference across reloads for the same file path.

Closes stablyai#10165

* refactor(editor): dedupe PDF zoom handlers into shared callbacks

Collapse six copies of the step-scale-and-record-preference logic (three
directions duplicated across the keyboard handler and toolbar callbacks)
into a single stepZoom callback; the keydown handler now reuses zoomIn/
zoomOut/zoomReset so keyboard and toolbar can't drift apart.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Jinjing <[email protected]>
Co-authored-by: Orca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] when PDFs are updated, the zoom resets

2 participants