Skip to content

Turn off visual zoom by default - #12679

Merged
ckerr merged 2 commits into
masterfrom
no-visual-zoom
Apr 26, 2018
Merged

ckerr merged 2 commits into
masterfrom
no-visual-zoom

Conversation

@nornagon

Copy link
Copy Markdown
Contributor

Ref #12631

Visual zoom can be re-enabled by webContents.setVisualZoomLevelLimits(1, 3) (see web_preferences.cc for more details on how the defaults are currently set).

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@ckerr
ckerr merged commit dd7e0f8 into master Apr 26, 2018
@ckerr
ckerr deleted the no-visual-zoom branch April 26, 2018 15:27
sindresorhus added a commit to sindresorhus/electron-util that referenced this pull request Sep 19, 2018
`webContents.setVisualZoomLevelLimits(1, 1);` is now the default in Electron: electron/electron#12679
huntharo added a commit to pwrdrvr/PwrSnap that referenced this pull request May 20, 2026
User linked electron/electron#12679 and the Electron docs explicitly
say: "Visual zoom is disabled by default in Electron. To re-enable
it, call w.webContents.setVisualZoomLevelLimits(1, 3)."

Crucially, "disabled" here means more than "no zoom happens" — when
visual zoom is off (the default), Chromium silently DROPS the
synthetic ctrl+wheel events that the OS dispatches for macOS
trackpad pinch. From the renderer's point of view, pinch is a no-
op event stream. That matches what the user saw: regular scroll
delivered wheel events with ctrlKey:false, pinch delivered nothing.

I previously tried setVisualZoomLevelLimits(1, 1) thinking it would
SUPPRESS browser zoom. Worst of both worlds: limits set, but min ===
max means no zoom range, and Chromium still treats it as "no pinch
interest." Removed it, then made it worse by adding it back
elsewhere. The user-pointed fix is the correct API call with a
non-degenerate range — (1, 3) per the docs.

The Editor's onWheel handler already preventDefaults wheel events
with ctrlKey/metaKey before the browser visually zooms, so the
(1, 3) range never actually engages the browser's visual viewport
— it's there purely as the "yes, dispatch pinch events" signal.

Both call sites added back:
  - preload (webFrame) — applies on renderer reload (Cmd+R)
  - main (webContents) — belt-and-suspenders for any renderer that
                          loads before the preload runs

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>
huntharo added a commit to pwrdrvr/PwrSnap that referenced this pull request May 20, 2026
… toolbar (#91)

* feat(editor): v1 polish — arrow fixes, zoom/pan, undo/redo, draggable toolbar

Round 1 of editor v1 improvements before the layer-tree (v2) editor
work begins.

Arrow geometry (packages/shared/src/arrow.ts):
  • Stroke now factors arrow length, not just image short-side.
    A long arrow on a wide-short image (e.g. 4000×600) used to clamp
    to STROKE_MIN_PX=4 and render as a hairline; now it scales up
    to ~13px via lengthPx/LENGTH_DIVISOR. Bounded by STROKE_MAX_PX.
  • Short-arrow correction: when headLengthPx > lengthPx, baseCenter
    used to land BEHIND `from` and the visual was an "inverted /
    missing arrowhead." Now we shrink head+stroke proportionally so
    headLength ≤ lengthPx, keeping a recognizable arrowhead silhouette.
  • 6 new failing tests added for these pathologies, all now passing.

Zoom + pan (apps/desktop/src/renderer/src/features/editor/useZoomPan.ts):
  • Pinch-to-zoom via wheel+ctrlKey (macOS trackpad rewrites pinch
    into synthetic ctrl+wheel — only way the renderer sees it).
  • ⌘0 fit-to-window, ⌘1 actual size (devicePixelRatio-aware so
    Retina captures render OS-1:1), ⌘+/⌘- step.
  • Pan with click-drag when scale > 1 OR Space held (Photoshop
    convention).
  • Floating ZoomChip showing percent + reset/1:1 buttons,
    bottom-right of canvas wrap.

Undo/redo (apps/desktop/src/renderer/src/features/editor/useUndoRedo.ts):
  • Session-memory stack (past + future), max depth 100.
  • Create / update / delete EditOps with proper inverses via the
    existing overlays:upsert / overlays:delete IPC.
  • ⌘Z / ⌘⇧Z / ⌘Y bindings — skipped when a text field has focus
    so browser-default text undo still works.
  • Skips recording when WE are replaying an op (undoApplyingRef
    flag), so AI-broadcast overlays don't pollute the stack.

Draggable EditToolbar (library/EditToolbar.tsx):
  • Drag handle at the left edge of the floating toolbar in Library
    Focus/Reel modes. Module-level position store persists across
    Stage remounts within an app session; resets on app launch.
  • Double-click handle to snap back to bottom-center default.
  • Clamped to viewport so users can't drag it off-screen.
  • New "Reveal" button at the right end, dispatches capture:reveal.

DetailRail polish:
  • Hide the "Editor" button when the rail is showing in Focus/Reel
    — the user is already in the editor; opening a standalone editor
    window is a confusing duplicate.

Text overlay sizing (Editor.tsx):
  • TextDraftInput now computes its CSS font size from the live
    canvas height to match what the committed SVG TextGlyph will
    render. Previously the input was a fixed 13px while the glyph
    rendered at ~10px CSS, causing the "text jumps in size on commit"
    bug. (The deeper "can't edit text after placement" bug requires
    a hit-test + selection layer — deferred past v1.)

716/733 unit tests passing (3 new arrow tests + 13 pre-existing).
E2E editor specs: 3/3 green.

* feat(editor): apply review followups — clean undo contract, cursor-anchored zoom, 1:1 tracking, file split, tests

Five followups from PR #91 review, all small and self-contained:

1. **recordUpdate id-preservation fix.** The hook exposed
   `recordUpdate(prevRow, nextRow)` but the underlying `overlays:upsert`
   IPC is INSERT-only — no UPDATE-by-id — so undoing an "update" would
   have created a duplicate row instead of restoring the prior state.
   Dropped `recordUpdate` from the public surface entirely and
   documented in `EditOp` that future edit-after-place flows should
   record two ops (delete + create) rather than have the hook
   fabricate an id round-trip the IPC doesn't support.

2. **Cursor-anchored zoom.** Pinch (wheel+ctrlKey) now keeps the
   canvas pixel under the cursor in place by adjusting `panX/panY` in
   lock-step with `scale`. Math derived from the transform identity
   `screen = containerCenter + offset*scale + pan`. Uses the
   *effective* scale-change (post-clamp) so the anchor stays accurate
   at the MIN_SCALE / MAX_SCALE limits.

3. **actualSize() window-resize tracking.** When the user clicks 1:1
   we now enter an "actual-size locked" mode; a ResizeObserver on the
   canvas container re-computes the 1:1 scale whenever the window
   resizes. The lock clears on any other zoom op (pinch, ⌘+, ⌘-, ⌘0)
   so the user can leave 1:1 freely.

4. **Editor.tsx file split (1086 → 635 lines).** Extracted:
     • `OverlaySvg.tsx` — OverlaySvg + ArrowGlyph + RectGlyph +
       HighlightGlyph + BlurGlyph + TextGlyph
     • `TextDraftInput.tsx` — inline-input component
     • `editor-types.ts` — Draft union + MIN_DRAG_LENGTH + rectFromDrag
   No behavior change; pure restructure for navigability.

5. **`useUndoRedo` unit tests.** Six tests covering record→undo for
   both `create` and `delete` ops, redo replay, redo-stack clearing on
   new ops, the `applyingRef` gate (verifying it doesn't get stuck
   true), and the MAX_DEPTH=100 cap.

All 796 unit tests pass (was 790; +6 for useUndoRedo).
TypeScript clean. Smoke + editor E2E green (one unrelated flake on
the storage popover spec — passes on retry).

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>

* fix(editor): EditToolbar drag — switch to position: fixed so left/top match getBoundingClientRect

The drag math uses viewport-relative coordinates from
`getBoundingClientRect()`, but the toolbar's CSS positioning is
`position: absolute` — making `left/top` positioned-ancestor-relative,
not viewport-relative. The Stage wrapper sits ~280px to the right of
the viewport edge (left sidebar width), so applying viewport coords as
absolute left/top double-offset the toolbar by exactly that gap. The
user saw "the toolbar jumps ~300px to the right of the mouse pointer"
on drag-start.

Fix: when a custom position is in effect, switch to `position: fixed`.
Fixed positioning is viewport-relative, matching the drag math's
coordinate space. The grip stays under the cursor.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>

* feat(editor): replace Reveal with Reset · fix capture:reveal post-PR-#90

Two related fixes after user reported "Reveal doesn't open Finder and
the icon looks like layers, not a folder."

1. capture:reveal handler: was checking flat_png_path first (null for
   all new captures since PR #90 dropped the paired PNG), then
   legacy_src_path (null for all new bundle-flow captures). Result:
   every modern capture failed the reveal lookup and the handler
   silently returned err. DetailRail's "File" button was broken for
   the same reason. Added bundle_path as a middle fallback —
   Finder can't open .pwrsnap but it WILL select the bundle in its
   containing folder, which is what "reveal" means.

2. EditToolbar: dropped the Reveal button entirely (file-management
   action, not an editing tool, and DetailRail's File button covers
   it now that #1 works). Replaced with a Reset button at the same
   slot:
     • Two-click confirm pattern. First click arms the button — it
       morphs to "Confirm? · N" (showing overlay count) in danger
       colors. Second click within ~3 s wipes every overlay via
       overlays:list + overlays:delete loop. The button auto-disarms
       after 3 s of no input and on capture switch.
     • Counter-clockwise arrow icon (clearly "revert / undo all")
       rather than the previous layered-papers icon (which read as
       "show layers" — confusing next to Arrow/Rect/Highlight/Blur).
     • EditToolbar self-tracks overlay count via overlays:list +
       events:overlays:changed subscription. No prop drill from
       Library — narrower lift.

The Reset action doesn't currently push individual delete ops to the
undo stack (the hook lives inside the chromeless Editor; Reset lives
in Library's EditToolbar). User who hits Reset chose a clean slate;
⌘Z after Reset replays the stack that was there before, which is
acceptable for v1. A "clear stack" hook method + Library-level state
lift would be the right v2.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>

* fix(editor): use tokenized danger colors for Reset armed state

The renderer color lint enforces that raw hex literals only live
inside :root or :root[data-theme=...]. My fallback values (#ff7a55)
on the var() calls tripped it. The --danger / --danger-soft /
--danger-border / --danger-text tokens already exist with sensible
values for both themes — drop the fallbacks and let the cascade
handle it.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>

* feat(desktop): canvas-grows zoom model + relocate zoom indicator

Replace the editor's transform:scale-inside-overflow:hidden zoom with
the standard canvas-grows model used by every photo editor: the
canvas element has explicit CSS width/height that grow with zoom,
the wrap is overflow:auto, scrollbars appear when zoomed in, and
panning manipulates wrap.scrollLeft/scrollTop directly. margin:auto
on the canvas centers it when smaller than the wrap (fit / zoomed
out) and collapses to zero when larger.

Drops the floating ZoomChip from over the image (alpha-blending
issues, sat on top of the canvas). Zoom indicator + Fit/1:1 buttons
now live in the floating EditToolbar (chromeless mode) and the
bottom EditorToolbar (full/embedded modes) — both stable surfaces
that never overlap the image. Stage tracks zoom state via Editor's
new onZoomChange callback and passes it down to EditToolbar.

Cursor-anchored zoom math rewritten for scroll-position anchoring:
compute the cursor's content-fraction over the pre-zoom canvas,
then set scrollLeft/scrollTop so the same fraction lands under the
cursor on the post-zoom canvas. Scroll write deferred via
queueMicrotask so React commits the new canvas size before we
clamp against scrollWidth.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): stop canvas-grows zoom from rocket-launching into the void

The user reported the image shrinking on its own, exponentially, the
moment they opened the editor — without touching anything. Classic
CSS-layout feedback loop kicked off by the canvas-grows refactor:

  1. `computeFit` used `wrap.clientWidth` (which INCLUDES padding) but
     the canvas has to fit inside the padding box. Canvas computed
     slightly bigger than the content area → triggered scrollbars.
  2. Scrollbar appearance shrunk `clientWidth`/`clientHeight` by ~15px,
     ResizeObserver fired, fit recomputed smaller, canvas shrunk,
     scrollbars no longer needed → disappeared → `clientWidth` grew
     back → fit larger → scrollbars back → ... exponential shrink.
  3. Pre-measurement fallback (only `aspect-ratio` set, no max-width)
     let the canvas size up to the <img>'s intrinsic dimensions on
     first paint, kicking the loop off before useZoomPan had a chance
     to land the explicit dimensions.
  4. The canvas with explicit width could pressure layout ancestors
     (editor-root → psl__stage-img) via flex's default min-width:auto.

Fixes:

  • `computeFit` now subtracts the wrap's CSS padding from
    `clientWidth`/`clientHeight` (the actual content box), plus a 1px
    sub-pixel-rounding safety margin.
  • Switched from `useEffect` to `useLayoutEffect` for the initial
    fit measurement so the canvas paints once with explicit
    dimensions — no fallback flash.
  • Added `.editor-canvas.is-pre-measured { max-width:100%;
    max-height:100% }` as a defense-in-depth backstop for the rare
    window between commit and useLayoutEffect.
  • `display: flex; align-items: safe center; justify-content: safe
    center` on the wrap (the "safe" keyword falls back to start when
    content overflows, fixing the scroll-to-top-left case).
  • `flex: none` on the canvas so flex doesn't shrink past explicit
    dimensions when zoomed.
  • `min-width: 0; min-height: 0` on the wrap so a large canvas
    can't pressure layout ancestors wider.
  • `width: 100%` on `.editor-root.is-chromeless` and `.is-embedded`
    so editor-root never sizes to its content's intrinsic width.
  • Sub-pixel-jitter rejection in the ResizeObserver: don't commit a
    new fit unless dimensions shifted by ≥0.5px. Stops thrashing on
    layout reflow.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): break stage-img content-size feedback in canvas-grows

The previous fix subtracted padding accurately but missed the
content-pressure feedback in psl__stage-img itself.

psl__stage-img has `aspect-ratio` inline + `max-width: 100% - 32px`
+ `max-height: 100% - 32px` — but NO explicit width/height. Its size
came from its content's intrinsic, then capped by max-w/max-h.

In the OLD code, the canvas had `aspect-ratio + max-width:100% +
max-height:100%`, which provided an intrinsic-size anchor that
propagated UP through editor-root → stage-img. That anchor was
content-independent (came from aspect-ratio + image dimensions).

In the NEW canvas-grows code, once useZoomPan sets explicit pixel
dimensions on the canvas, the canvas's intrinsic IS that explicit
size. Each iteration:
  • Canvas explicit width = wrap.clientWidth - padding - 1px safety
  • Canvas's explicit width becomes wrap's intrinsic min-content
  • editor-root.intrinsic = wrap.intrinsic = canvas width
  • stage-img.auto-width = editor-root.intrinsic = canvas width
  • Wrap.clientWidth = stage-img.width = canvas width - 1px slower
  • Next ResizeObserver fire reads the now-smaller wrap
  • Fit shrinks by 1px → canvas shrinks by 1px → stage-img shrinks
    by 1px → repeat ad infinitum

The -1px safety margin (added to prevent sub-pixel overflow) was
leaking out of the canvas every iteration, causing the exponential
"rocket launching away" shrink toward 0.

Fix: change psl__stage-img from purely max-bounded to explicitly
width-bounded (`width: calc(100% - 32px)`) so its size is
independent of content. The aspect-ratio + max-height combination
then resolves to object-fit:contain semantics relative to the
stage-wrap area, preserving the visual "framed photo" look without
the content-pressure cycle.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(desktop): single-button zoom menu + fix pinch zoom + last layout cycle

Two bugs + one redesign in one pass.

LAYOUT CYCLE (the last one).

The previous stage-img fix decoupled stage-img from canvas content,
but editor-root's grid still had `grid-template-columns: none` —
which means one implicit `auto` column sized to its content's
max-content. The wrap's max-content is the canvas's explicit pixel
width, so the canvas could STILL pressure editor-root's column track
back up the chain. Pinch-zooming made the canvas grow → column track
grew → wrap grew → fit grew → canvas grew more → exponential GROWTH
this time (the inverse of the earlier shrinkage).

Fix: `grid-template-columns: 1fr` on every editor-root variant so
the column track always fills editor-root's width, never sized by
content. Canvas can grow past wrap freely with overflow:auto
scrollbars, parent layout stays stable.

PINCH ZOOM RACE.

The wheel listener attached with `useEffect(() => {...}, [zoom, ...])`
where `zoom` is a new object every render. Effect re-ran every
render, detaching and reattaching the listener. Trackpad pinch fires
~60 wheel events/sec; the microsecond window between cleanup and
re-add was wide enough to drop events. User perceived "pinch zoom
doesn't work."

Fix: attach the listener ONCE on mount, read `zoom.onWheel` through
a ref that's updated each render.

ZOOM UX REDESIGN.

Replaced the confusing "100% | 1:1" pair (where clicking 100% did
"fit" and clicking 1:1 did "actual size," both buttons changing
their own label after click) with a single ZoomMenu button that
shows the current zoom state in its label and opens a popover for
mode selection:

  • Label: "Fit (62%)" when mode=fit, "100%" when mode=actual,
    "150%" when mode=custom. The parenthetical pct in fit mode
    surfaces the real zoom level (Retina captures sit at ~50% in
    fit mode, which used to be confusing).
  • Popover: Fit row (with ⌘0 hint), 100% row (with ⌘1 hint), and
    a custom-pct row with −20%, text input, +20% controls.
  • Selected mode gets a checkmark + accent color.
  • Text input commits on Enter or blur; Escape cancels.
  • Pinch-zoom / keyboard ⌘+/⌘- flip mode to "custom" automatically.
  • Live update in the input as zoom changes from other sources.

useZoomPan now exposes `mode`, `displayPct`, `fitPct`, `setCustomPct`,
and `zoomBy(factor)` so the menu can drive scale directly. Replaced
the old `actualSizeLocked` boolean with the more general `mode`
enum. The hook's API matches what the menu needs; the menu doesn't
care about internal scale.

ZoomMenu lives in features/editor/ with its own ZoomMenu.css using
neutral `ed-zoom-*` class names so both the Library's floating
EditToolbar (which doesn't import editor.css) and the standalone
Editor window (which doesn't import library.css) pick up the
styling through the component import.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): unbreak pinch zoom + let canvas grow into full stage area

Two issues:

PINCH ZOOM NOT FIRING.

The library window didn't have `setVisualZoomLevelLimits(1, 1)`,
so Electron/Chromium's built-in visual viewport pinch zoom was
consuming trackpad pinch gestures BEFORE they reached the Editor's
wheel-with-ctrlKey listener. The other windows (tray, float-over,
settings) already had this — library was the holdout because pinch
behavior there had been deferred to "later." It's now later.

CANVAS CLIPPED TO STAGE-IMG'S ASPECT-RATIO BOX.

`psl__stage-img` had `aspect-ratio: W/H` set inline (matching the
image's exact aspect), with `overflow: hidden`. When the user zoomed
in past fit, the canvas grew correctly but was clipped to the
aspect-ratio-shaped stage-img — the rest of the available stage
area (the empty letterbox/pillarbox regions and the breathing room)
was unreachable to zoomed content. User wanted the canvas to extend
into the full available space.

Fix: drop the inline aspect-ratio from stage-img. It's now a
RECTANGULAR viewport sized to fill stage-wrap minus 32px. The
"framed photo" visual chrome (border + border-radius + box-shadow)
moved off stage-img — it's already on .editor-canvas, where it
matches the image aspect at fit AND grows with the canvas under
zoom. stage-img is now a transparent passthrough whose only job is
to bound the canvas-grows viewport.

At fit: image fills the image-aspect canvas (with its own framing),
centered inside the rectangular stage area. The viewer sees a
framed photo on a clean stage — same as before.

At zoom > 1: canvas grows past the stage area, wrap shows
scrollbars on the wrap's overflow:auto, user can pan to see the
zoomed-in content. Frame grows with the canvas.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): remove touch-action that was blocking pinch zoom

I added \`touch-action: pan-x pan-y\` to .editor-canvas-wrap during
the canvas-grows refactor, thinking it would suppress the browser's
native pinch zoom in favor of our wheel handler. It "looked"
correct — pan-x and pan-y are allowed, no zoom — but Chromium has
an undocumented (in the CSS spec, anyway) behavior where
\`touch-action\` ALSO suppresses the synthetic ctrl+wheel events
the OS dispatches for trackpad pinch gestures. Declaring pan-only
silently killed the gesture-to-wheel pipeline that the Editor's
zoom handler depends on.

Per Chromium dev docs, "touch-action also affects how wheel events
are routed to handlers" — pan-only effectively says "I don't want
to handle pinch zoom here," and the browser stops synthesizing the
events.

Browser-level visual-viewport pinch is already disabled at the
webContents level via setVisualZoomLevelLimits(1, 1) (the previous
commit), so we don't need touch-action to suppress browser zoom.
Default \`touch-action: auto\` is correct here.

This is the regression the user was seeing: pinch zoom worked
before the refactor (no touch-action then) and stopped working
after.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): attach Editor wheel listener at window-level capture

Trackpad pinch zoom still wasn't firing even after removing
\`touch-action\` and adding setVisualZoomLevelLimits(1, 1). Move the
wheel listener from the wrap element (bubble phase) to the window
(capture phase) so we catch the events before any intermediate
element can stopPropagation or otherwise hide them from us.

Filter the handler by \`wrap.contains(e.target)\` so wheel events
over the DetailRail, sidebar, popover, etc. pass through normally —
only events targeting inside the canvas-wrap trigger editor zoom.

This is defense in depth: if the event flow IS reaching the wrap
fine and the previous fixes had landed, this change is a no-op
behaviorally (same handler called for the same events). If the
event flow was NOT reaching the wrap for any reason (overflow:auto
interaction, parent stopPropagation, gesture routing oddities),
this catches it.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(desktop): add macOS gesturestart/change/end pinch fallback

User reports NO wheel events at all (verified with a window-level
capture-phase listener) when trying to pinch on the macOS trackpad,
even after the touch-action removal and setVisualZoomLevelLimits(1,
1) on the library window.

Two possible explanations:
  1. Chromium isn't synthesizing wheel-with-ctrlKey events at all
     on the user's machine for trackpad pinch (Chromium version,
     hardware, or main-process state issue).
  2. The user hasn't fully restarted the dev process so
     setVisualZoomLevelLimits hasn't been applied to the current
     window instance.

Belt-and-suspenders fix: add macOS gesturestart/change/end events
as a parallel zoom path. These are WebKit-style events that
Chromium ALSO dispatches on macOS for trackpad pinch gestures —
typically more reliable than the wheel synthesis because they're
the native gesture pipeline, not a synthetic translation.

- useZoomPan exposes onGestureStart/Change/End handlers alongside
  onWheel. Both drive a shared zoomAtCursor(factor, x, y) internal
  function so the cursor-anchored math is identical for both paths.
- Editor.tsx attaches all four (wheel + three gesture events) at
  window-level capture phase with the same wrap.contains(target)
  filter. Whichever pipeline Chromium uses on the user's machine,
  we'll catch it.
- event.scale on gesturechange is CUMULATIVE since gesturestart;
  we track gestureScaleRef to compute the incremental factor per
  change event.

Refactored onWheel to use the shared zoomAtCursor helper instead
of inlining the math.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): disable browser pinch zoom from preload via webFrame

User reports no wheel/gesture events firing for trackpad pinch at
all — Chromium is consuming the gesture for its built-in page-zoom
before it reaches the renderer's JavaScript.

The previous attempt called \`webContents.setVisualZoomLevelLimits\`
from main (window.ts). That has two problems:
  1. Main-process changes need a full \`pnpm dev\` restart to apply
     to an existing window; the user almost certainly didn't
     restart, so the setting wasn't in effect.
  2. Even with a restart, the call happens after the window's
     webContents object exists but the timing relative to first
     input handler initialization isn't guaranteed.

Move the call into the preload via \`webFrame.setVisualZoomLevelLimits\`.
That executes inside the renderer process at preload-load time —
BEFORE any input event reaches the renderer's JavaScript, and
re-runs on every renderer reload (Cmd+R), no main-process restart
needed.

No window in PwrSnap wants browser-level pinch zoom (the library
editor handles its own; tray, settings, float-over, capture are all
fixed-layout), so applying it globally from the shared preload is
correct.

Wrapped in try/catch — setVisualZoomLevelLimits can throw if the
frame isn't fully initialized in some Electron versions; the
existing main-side fallback covers that edge.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): revert setVisualZoomLevelLimits — it suppressed pinch

Found the actual regression by comparing the working state (3490195,
pre-canvas-grows) with the current state. At 3490195, there was NO
setVisualZoomLevelLimits call anywhere, and pinch zoom worked via
the natural wheel-with-ctrlKey synthesis Chromium uses on macOS.

I introduced setVisualZoomLevelLimits in two places thinking it
would HELP — disable browser visual zoom so our canvas handler
could take the gesture. Backwards. Pinning the visual viewport at
1× tells Chromium "this page can't zoom," and Chromium then stops
synthesizing the wheel-with-ctrlKey events the renderer needs to
detect pinch in the first place. Net effect: no events at all
reach the page, exactly what the user reported.

The Editor's onWheel already calls event.preventDefault() the
moment ctrlKey is set, which prevents page-level zoom WITHOUT
disabling the event pipeline. That's the correct way to keep
trackpad pinch while suppressing browser zoom.

Removed from:
  - apps/desktop/src/preload/index.ts (renderer-side webFrame call)
  - apps/desktop/src/main/window.ts (createMainWindow's webContents
    call)

The tray, float-over, settings, and capture windows keep their
setVisualZoomLevelLimits(1, 1) calls because they have no pinch
handler at all and intentionally want pinch to be a no-op.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): overflow:hidden on wrap + transform-based pan (pinch fix)

Final theory after diffing against the last-known-good state
(3490195, pre-canvas-grows): the regression was \`overflow: auto\`
on the canvas-wrap. Confirmed by tracing every CSS difference
since the working commit; everything else either no-op'd or was
reverted along the way.

CHROMIUM'S OVERFLOW-AUTO PINCH ROUTING.

When the cursor's containing element has \`overflow: auto\`
(meaning it's a scroll container), Chromium on macOS routes
trackpad pinch as a scroll gesture rather than synthesizing the
wheel-with-ctrlKey events the renderer needs to handle pinch
zoom. The events never reach JavaScript at all — the user's
debug listener at window-level capture phase saw NOTHING for
pinch. That's the smoking gun.

\`overflow: hidden\` makes the wrap a non-scroll container, and
Chromium reverts to the normal wheel synthesis path. Same fix
worked at 3490195 (overflow:hidden, pinch worked) before I broke
it in b7672da (canvas-grows refactor introduced overflow:auto).

TRANSFORM-BASED PAN.

With \`overflow: hidden\`, \`wrap.scrollLeft/scrollTop\` is a no-op
visually (no scroll container = nothing to scroll). Switched the
pan implementation to \`transform: translate(panX, panY)\` on the
canvas itself:

  - Added panX/panY to ZoomPanState (state.scale was the only
    field before).
  - canvasStyle now emits \`transform: translate(panX, panY)\` on
    top of the explicit width/height.
  - onPanPointerMove updates panX/panY via setState instead of
    writing to wrap.scrollLeft.
  - resetToFit/actualSize/setCustomPct reset panX/panY to 0.
  - zoomBy (±20% from the menu) preserves panX/panY.
  - zoomAtCursor (cursor-anchored zoom for wheel + gesture)
    computes nextPanX/panY directly from the cursor's
    content-fraction math — clean closed-form, no scroll-write
    microtask race anymore.

The canvas is laid out by the wrap's flex centering; transform
adds on top. So topLeft = (wrapContentSize - canvasSize) / 2 + pan
holds whether canvas is smaller or larger than the wrap. When
larger, parts protrude past the wrap edges; overflow:hidden clips
them. Drag (or pinch with cursor anchor) shifts panX/panY to
reveal different parts.

REVERT scrollbar-gutter / safe center / extra defensive comments
that were specific to the overflow:auto model — they're no longer
load-bearing.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* chore(desktop): temporary console.warn diagnostics in editor zoom listeners

User reports no wheel or gesture events fire on macOS trackpad pinch
even with overflow:hidden + transform-pan. Hard to debug remotely
without seeing what (if anything) reaches the renderer.

Added a single \`console.warn\` on listener attach (proves the
effect ran), plus one inside each of the four event handlers (wheel,
gesturestart/change/end). They prefix with "[Editor ...]" so the
user can easily grep DevTools console output.

Will revert these once pinch is confirmed working.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(desktop): Figma-style two-finger interactions (pan + ⌘+scroll zoom)

Confirmed via the diagnostic logs: regular two-finger scroll DOES
dispatch wheel events on the user's machine, but pinch silently
drops — Chromium isn't synthesizing the ctrl+wheel events for
trackpad pinch on this configuration. That depends on macOS
trackpad settings ("Zoom in or out" in System Settings → Trackpad
→ Scroll & Zoom), accessibility config, and Chromium version, none
of which JS can control.

Rather than fight the gesture pipeline, give the user a reliable
canvas-editor interaction model that doesn't depend on pinch at
all. Figma / Sketch / Excalidraw all do this:

  • Two-finger scroll  → pan canvas (deltaX, deltaY shift the
                          translate)
  • ⌘ + scroll          → zoom (cursor-anchored, exponential)
  • ⌘+ / ⌘- keyboard   → zoom (already wired)
  • Zoom menu buttons  → Fit / 100% / custom %
  • Pinch (if available) → still zooms (dispatches as ctrl+wheel
                            when it works; same handler runs)

The wheel handler no longer early-returns on un-modified wheel —
it now pans. The zoom path is unchanged (still requires ctrl or
meta modifier). Pinch users on configurations where Chromium DOES
synthesize ctrl+wheel still get pinch zoom for free; users where
it doesn't dispatch get ⌘+scroll instead.

Removed the temporary console.warn diagnostics from Editor.tsx now
that the listener pipeline is confirmed working.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): re-enable pinch via setVisualZoomLevelLimits(1, 3)

User linked electron/electron#12679 and the Electron docs explicitly
say: "Visual zoom is disabled by default in Electron. To re-enable
it, call w.webContents.setVisualZoomLevelLimits(1, 3)."

Crucially, "disabled" here means more than "no zoom happens" — when
visual zoom is off (the default), Chromium silently DROPS the
synthetic ctrl+wheel events that the OS dispatches for macOS
trackpad pinch. From the renderer's point of view, pinch is a no-
op event stream. That matches what the user saw: regular scroll
delivered wheel events with ctrlKey:false, pinch delivered nothing.

I previously tried setVisualZoomLevelLimits(1, 1) thinking it would
SUPPRESS browser zoom. Worst of both worlds: limits set, but min ===
max means no zoom range, and Chromium still treats it as "no pinch
interest." Removed it, then made it worse by adding it back
elsewhere. The user-pointed fix is the correct API call with a
non-degenerate range — (1, 3) per the docs.

The Editor's onWheel handler already preventDefaults wheel events
with ctrlKey/metaKey before the browser visually zooms, so the
(1, 3) range never actually engages the browser's visual viewport
— it's there purely as the "yes, dispatch pinch events" signal.

Both call sites added back:
  - preload (webFrame) — applies on renderer reload (Cmd+R)
  - main (webContents) — belt-and-suspenders for any renderer that
                          loads before the preload runs

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(desktop): only preventDefault wheel events when we're handling zoom

User intuition: unconditional preventDefault on every wheel event
signals Chromium that the page "owns" wheel handling. Chromium
then stops synthesizing the synthetic ctrl+wheel events for macOS
trackpad pinch — the gesture is suppressed because the page would
just preventDefault it anyway.

That explains the silent pinch even after re-enabling visual zoom
via setVisualZoomLevelLimits(1, 3). The setting allowed Chromium
to dispatch pinch-as-wheel, but our preventDefault'ing on every
wheel event (added for the Figma-style pan branch) told Chromium
not to bother.

Now preventDefault only when actually handling zoom (ctrl/meta
modifier). The pan branch updates panX/panY ourselves; default
wheel behavior on the overflow:hidden wrap is a no-op so there's
no visible conflict from letting the event bubble.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* chore(desktop): re-add wheel/gesture diagnostic logs

User reports ctrl+scroll zoom and two-finger pan both work (so the
onWheel handler IS being called) but says \"nothing logs to
console\" — because I removed the console.warn diagnostics
prematurely in 2a56fb4. Adding them back temporarily so we can
verify whether pinch dispatches a wheel event the handler ignores,
or doesn't dispatch at all.

Will revert these once pinch is sorted.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* chore(desktop): finalize zoom interactions, drop diagnostic logs

Confirmed via diagnostic logs: Chromium on the user's machine does
not dispatch ANY events (wheel-with-ctrlKey, gesturestart/change/
end) for trackpad pinch — even with setVisualZoomLevelLimits(1, 3)
and conditional preventDefault. Pinch silence is a Chromium /
macOS-level behavior we can't reach from JavaScript.

That's fine. Accepting the limit and shipping the working set:

  • ⌘ + scroll       → zoom (cursor-anchored)
  • Ctrl + scroll    → zoom (Windows / cross-platform convention)
  • Two-finger scroll → pan canvas
  • ⌘+ / ⌘-          → zoom step (keyboard)
  • ⌘0               → fit to window
  • ⌘1               → 100% (DPR-aware actual size)
  • Zoom menu button → Fit / 100% / custom % entry / ±20%
  • Pinch            → zoom IF Chromium dispatches it on the
                        config (handler is there, just unreliable)

These are the same interactions Figma / Sketch / Excalidraw ship
with — pinch dispatch is unreliable enough that no professional
canvas editor relies on it as the only zoom path.

Cleanup:
  - Removed diagnostic console.warn from the wheel/gesture listener
    attach (Editor.tsx).
  - Documented why the gesture-event handlers stay in defense-in-
    depth.
  - Updated the ZoomMenu button title attribute to list the
    working shortcuts (⌘0/⌘1/⌘+/⌘-/⌘+scroll/two-finger pan).

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(editor): surface zoom shortcuts visibly in ZoomMenu

User couldn't see the title-attribute tooltip in light mode (native
HTML tooltips are unreliable in Electron — they're rendered by the
OS and can blend with the surface in some color schemes). Move the
shortcut hints into the menu body where they're always
discoverable.

  - ⌘- / ⌘+ keys now annotate the ± step buttons (anchored to the
    bottom-right corner of each, fading in on hover so they don't
    clutter at rest).
  - A small footer line below the custom-pct row spells out
    "⌘+scroll cursor zoom · two-finger scroll pans" — the only
    interactions that don't have a discoverable button or menu
    row of their own.
  - Dropped the redundant title attributes from the step buttons
    (the inline hint is the new source of truth).

Aria labels kept on the step buttons for screen readers; the
visible ⌘± hints are aria-hidden so they don't double-announce.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(editor): shorten ZoomMenu button title to just \"Zoom\"

The native title attribute on the toolbar button was still carrying
the full shortcut list — and the OS tooltip renderer wraps that
into a hard-to-read multi-line block that obscures the canvas.
Now that the open menu surfaces every shortcut inline (⌘0/⌘1 on
the Fit/100% rows, ⌘± on the step buttons, and a footer line for
⌘+scroll + two-finger pan), the long title is redundant.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(editor): draw with the active tool, don't hijack drag to pan

Regression from the canvas-grows + transform-pan refactor: when
zoomed in (scale > 1), single-finger drag on the canvas always
panned, even if a drawing tool was selected — so the user couldn't
draw an arrow / rect / highlight on the zoomed-in image.

Tightened the wantPan arbitration:

  • Space held         → pan (Photoshop convention, every tool)
  • Pointer + zoom>1   → pan (Pointer is the no-op-on-drag tool,
                          drag is free for navigation)
  • Any drawing tool   → tool draws; pan stays available via
                          Space+drag and two-finger scroll

Two-finger scroll for pan is unaffected — it's handled by the
wheel listener in useZoomPan, not the canvas pointer handlers,
so it never conflicts with single-finger tool drag.

🤖 Generated with Claude Opus 4.7 via [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.5 <[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.

2 participants