feat: expose setZoom and getZoom API on SuperDoc#1498
feat: expose setZoom and getZoom API on SuperDoc#1498tupizz wants to merge 5 commits intosuperdoc-dev:mainfrom
Conversation
Add public methods to programmatically control zoom level:
- `setZoom(percent)` - Set zoom level (e.g., 150 for 150%)
- `getZoom()` - Get current zoom level as percentage
This allows developers to implement custom zoom controls
without relying on the toolbar UI.
Usage:
```javascript
// Set zoom to 150%
superdoc.setZoom(150);
// Get current zoom
const zoom = superdoc.getZoom(); // Returns 100, 150, etc.
// Listen for zoom changes
superdoc.on('zoomChange', ({ zoom }) => {
console.log(`Zoom changed to ${zoom}%`);
});
```
Closes superdoc-dev#928
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR adds programmatic zoom control to SuperDoc by exposing setZoom() and getZoom() public API methods, along with a zoomChange event. This enables developers to implement custom zoom controls (e.g., keyboard shortcuts, custom UI buttons, gesture controls) without relying on the built-in toolbar.
- Adds
getZoom()method to retrieve current zoom level as a percentage - Adds
setZoom(percent)method to programmatically set zoom level for all documents - Emits
zoomChangeevent when zoom is changed programmatically
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add 8 test cases covering: - getZoom returns 100 when no presentation editor is available - getZoom returns correct percentage from presentation editor - getZoom rounds to nearest integer - setZoom calls presentation editor with correct multiplier - setZoom emits zoomChange event - setZoom updates all editors in multi-document mode - setZoom handles invalid values gracefully - setZoom handles missing presentation editor
476c981 to
84f915c
Compare
|
@edoversb 🙏🏻 |
84f8ea5 to
2a443d8
Compare
# Conflicts: # packages/superdoc/src/core/SuperDoc.test.js
- setZoom: also update superdocStore.activeZoom so toolbar UI stays in sync with programmatic zoom changes - getZoom: fall back to store value when PE is not yet available - onToolbarCommand: route toolbar zoom through setZoom() instead of direct store mutation, ensuring consistent behavior - dev app: add zoom +/- buttons for manual testing
512decf to
df86c8b
Compare
|
merged via #2137 |
Demo
CleanShot.2026-02-19.at.13.33.58.mp4
Summary
Add public methods to programmatically control zoom level on SuperDoc instances:
setZoom(percent)- Set zoom level as a percentage (e.g., 150 for 150%)getZoom()- Get current zoom level as percentagezoomChangeevent - Emitted when zoom changesThis allows developers to implement custom zoom controls (e.g., Ctrl+scroll, pinch-to-zoom, custom UI buttons) without relying on the toolbar.
Implementation
Both
setZoomandgetZoomgo throughsuperdocStore.activeZoom— the same centralized state used by the toolbar's zoom dropdown. The Vue watcher onactiveZoompropagates changes to all downstream systems:PresentationEditor.setGlobalZoom()— all editorspdfViewer.updateScale()— PDF viewerThis ensures overlays, comment highlights, hit-testing, and PDF rendering all stay in sync with the zoom level.
Usage
Test plan
setZoom(150)updatessuperdocStore.activeZoomto 150getZoom()returns currentactiveZoomfrom storegetZoom()reflects value set bysetZoom()(round-trip)zoomChangeevent fires with correct payloadReferences
Closes #928
Closes SD-1221