Repository navigation
fix(editor): preserve PDF zoom when file content reloads - #10168
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughPDF zoom management now uses shared helpers for clamping, applying, and stepping scale preferences. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/renderer/src/components/editor/PdfViewer.tsxsrc/renderer/src/components/editor/pdf-scale-preference.test.tssrc/renderer/src/components/editor/pdf-scale-preference.ts
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
left a comment
There was a problem hiding this comment.
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.
) * 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]>
Summary
currentScaleValue = 'page-width', so any user zoom was lost after an on-disk update.Fixes #10165
Test plan
pdf-scale-preferenceapply / step / clamp