Skip to content

fix(editor): route zoom gestures to PDF viewer - #17241

Closed
moeinfinityx wants to merge 2 commits into
stablyai:mainfrom
moeinfinityx:moeinfinityx/pdf-gesture-zoom
Closed

moeinfinityx wants to merge 2 commits into
stablyai:mainfrom
moeinfinityx:moeinfinityx/pdf-gesture-zoom

Conversation

@moeinfinityx

@moeinfinityx moeinfinityx commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Zoom gestures and shortcuts now zoom the PDF itself instead of changing Orca’s editor font size.

What Changed

  • Added cursor-centered Ctrl+scroll and trackpad-pinch zoom to the PDF viewer.
  • Added Command+scroll support on macOS.
  • Routed the configured zoom-in, zoom-out, and reset shortcuts to the active PDF.
  • Preserved PDF zoom bounds and the current zoom preference across content reloads.
  • Ensured hidden PDFs and PDFs in unfocused split panes do not receive zoom commands.
  • Added regression coverage for pdf.js’s uninitialized scale, which previously caused the first gesture to jump to 10%.

Why

Electron captures standard zoom commands before the PDF viewer receives them. Because an open PDF uses an editor tab, those commands were incorrectly routed to editor-font zoom, which has no visible effect on the document.

The PDF viewer now claims zoom input only when it is the active target and uses pdf.js’s existing scaling API with the pointer position as the zoom origin.

Linked Issue

N/A

Visual Proof

N/A, No visible UI changes are made, only hotkey behavior changed.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Validated with:

  • Focused PDF scale, command-routing, and zoom-target tests
  • Regression test for the pdf.js unknown-scale 10% jump
  • Renderer web typecheck
  • Changed-file lint and React Doctor profiles
  • Max-lines ratchet
  • Electron E2E-mode bundle build

Automated coverage includes Linux/Windows Ctrl modifiers, macOS Command-wheel, trackpad-style Ctrl-wheel events, scale bounds, pointer-origin scaling, hidden viewers, and focused split-pane ownership.

AI Disclosure

OpenAI Codex (GPT-5.6 Sol) was used to implement this change. Code are manually reviewed and tested.

Review

Review focus:

  • First-gesture behavior when pdf.js has not initialized its private numeric scale
  • Active PDF ownership across split panes and hidden worktrees
  • Compatibility with customized global zoom keybindings

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no new preload APIs, IPC channels, filesystem access, or remote commands.
  • Cross-platform: supports Ctrl on Windows/Linux and Command on macOS while retaining Ctrl-based pinch events.
  • SSH/remote: renderer-only behavior; no execution-host or wire-protocol changes.
  • Mobile: no mobile code paths changed.
  • Performance: wheel handling uses a scoped non-passive listener mounted only with the PDF viewer.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR routes wheel gestures, configured shortcuts, and Electron zoom commands to the active PDF viewer while retaining zoom preferences across document reloads.

  • Adds cursor-centered, bounded PDF wheel scaling with uninitialized-scale handling.
  • Selects the active PDF using file, worktree, split-pane, and visibility state.
  • Rebinds native wheel handling when the viewer container is replaced.
  • Adds tests for scaling, ownership, listener lifecycle, and command dispatch.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/renderer/src/components/editor/PdfViewer.tsx Integrates the dedicated PDF zoom-input hook and retains existing find and toolbar behavior.
src/renderer/src/components/editor/use-pdf-zoom-input.ts Owns native wheel handling, configured shortcut routing, command subscription, and listener rebinding.
src/renderer/src/components/editor/pdf-scale-preference.ts Adds bounded wheel-scale calculations, pointer-origin application, and platform modifier detection.
src/renderer/src/lib/pdf-zoom-command.ts Introduces active-viewer ownership checks and a cancelable renderer-local PDF zoom command channel.
src/renderer/src/hooks/ipc-events/zoom-ipc-bridge.ts Gives the active PDF first refusal on Electron zoom commands before existing editor and UI routing.
src/renderer/src/components/editor/use-pdf-zoom-input.test.ts Covers native wheel-listener migration when the PDF container is replaced.
src/renderer/src/components/editor/pdf-scale-preference.test.ts Covers wheel direction, bounds, modifier handling, pointer origin, and unknown initial scale.
src/renderer/src/lib/pdf-zoom-command.test.ts Covers active split-pane selection, hidden viewers, legacy ownership, and command claiming.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Zoom input] --> B{Input source}
  B -->|Ctrl or Command wheel| C[PDF container wheel listener]
  B -->|Configured shortcut| D[Active PDF target check]
  B -->|Electron zoom command| E[PDF command dispatch]
  E --> D
  C --> F[Compute bounded cursor-centered scale]
  D -->|Active PDF| G[Apply zoom command]
  D -->|No active PDF| H[Allow existing zoom routing]
  F --> I[Update PDF scale preference]
  G --> I
Loading

Reviews (2): Last reviewed commit: "fix(editor): rebind PDF wheel zoom after..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 29, 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: 63592afb-bbee-4c36-9dfa-2a032b26e37e

📥 Commits

Reviewing files that changed from the base of the PR and between 6d4cb90 and e9c19c5.

📒 Files selected for processing (3)
  • src/renderer/src/components/editor/PdfViewer.tsx
  • src/renderer/src/components/editor/use-pdf-zoom-input.test.ts
  • src/renderer/src/components/editor/use-pdf-zoom-input.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/editor/PdfViewer.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

PDF zoom handling now uses a shared command event system and active-target detection. The usePdfZoomInput hook handles zoom commands, wheel input, and zoom keybindings. Wheel scaling supports bounds, cursor-origin updates, and platform-specific modifiers. Terminal zoom commands stop at the PDF viewer when it claims the command. Tests cover target detection, command dispatch, wheel scaling, bounds, listener replacement, and modifier handling.

Merge Risk: 🟡 Moderate · up to e9c19

The PR routes zoom gestures and shortcuts to PDFs, but current behavior can still zoom an inactive split-pane PDF and may stop responding after an error-view remount. These localized correctness issues should be fixed or explicitly accepted before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the change, motivation, testing, review focus, platform impact, and checklist items. However, the required Linked Issue section contains "N/A" even though the template require… Add the issue reference in the required format, such as "Fixes #123", and retain the existing explanation and testing details.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: routing editor zoom gestures to the PDF viewer.
Full details: Description check

Explanation

The description explains the change, motivation, testing, review focus, platform impact, and checklist items. However, the required Linked Issue section contains "N/A" even though the template requires an issue link.

  • Fix all pre-merge checks with AI

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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f1ca837b-4a48-4d86-8093-be8e99fd8918

📥 Commits

Reviewing files that changed from the base of the PR and between a1f198b and 6d4cb90.

📒 Files selected for processing (7)
  • 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
  • src/renderer/src/components/editor/use-pdf-zoom-input.ts
  • src/renderer/src/hooks/ipc-events/zoom-ipc-bridge.ts
  • src/renderer/src/lib/pdf-zoom-command.test.ts
  • src/renderer/src/lib/pdf-zoom-command.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@moeinfinityx

Copy link
Copy Markdown
Contributor Author

Remount rebinding is fixed in e9c19c5. Inactive-pane wheel zoom is intentionally pointer-owned, consistent with the image viewer; keyboard and menu zoom remain active-pane-owned. No further changes are planned for these items.

@Waynting

Waynting commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

I'd really like to see this land — pinch and Ctrl/⌘+scroll zoom feel like baseline expectations for a PDF viewer, and right now neither works.

I checked this PR against current main (4ea021f919):

  • It still applies cleanly (3-way merge, no conflicts).
  • pnpm tc:web passes, the PDF/zoom unit tests pass (8 files, 68 tests), and oxlint is clean on the changed files.
  • I ran the same Playwright E2E probe against the hidden Electron app with and without this PR:
Action on an open PDF main With this PR
Ctrl+scroll up (what a trackpad pinch sends) stays at 100% 100% → 140%
Ctrl+scroll down no change 140% → 100%
⌘+scroll up (macOS) no change 100% → 140%
Plain scroll scrolls, zoom unchanged scrolls, zoom unchanged
View → Zoom In (the ⌘/Ctrl+= path) PDF unchanged, editor font zoom goes 0 → 1 PDF 140% → 175%, editor font zoom unchanged

So the last row also confirms the bug described above: on main, the zoom shortcut silently changes the editor font size instead of zooming the PDF.

@Jinwoo-H @nwparker — since you've both worked on the PDF viewer recently, would one of you be able to review this? Thanks!

@Jinwoo-H

Jinwoo-H commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Hey @moeinfinityx, thanks for digging into this, and sorry it sat so long! You found the real cause: main takes the zoom shortcuts before the PDF's keydown handler runs. Hooking the zoom bridge and reusing the image viewer's pinch math were both the right calls.

While testing on current main we hit a few gesture issues:

  • pdf.js updateScale rounds to 0.01, so slow trackpad pinches (1–3px deltas) don't move at all.
  • The origin is in window coordinates, but pdf.js measures it from the container's offsetTop/offsetLeft, so the content under the cursor drifts by the pane's offset.
  • Wheel zoom isn't written to the saved PDF zoom that landed on main after you branched.

We also found the editor pane already knows which pane is focused (the same signal Cmd+S uses). So instead of each viewer working it out from the store and the DOM, we put the wheel listener inside the pdf.js session and set absolute scales anchored at the pointer. The PDF in the focused pane takes the zoom command through a small React context. We also made pinch a bit faster while we were there.

That version is up in #26652, with your commit credited as co-author. Thanks again for the thorough PR description and tests! 🙏

@moeinfinityx

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review and for getting this merged! The fixes and the focused-pane approach make a lot of sense, and I appreciate the co-author credit. I’ll close this PR in favor of #26652. 🙏

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.

3 participants