Skip to content

mac: preview pinch-to-zoom no longer swallowed by the editor's font-size magnifier - #674

Merged
GoKubar merged 1 commit into
mainfrom
agent/claude/fix-preview-pinch-zoom
Sep 16, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/claude/fix-preview-pinch-zoom

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Owner: pinch-to-zoom on the preview used to work and no longer does (or works badly).

Investigation. PreviewZoom.swift's PreviewMagnify/MagnificationGesture on the preview itself is byte-for-byte unchanged since before the appearance overhaul (#653/#666) — git diff against the pre-overhaul commit on this file is empty — so the regression is not a code change to the gesture itself. Nothing else about ordinary preview interaction (clicks, navigation) was reported broken, which points at the one thing in this area that is not part of normal SwiftUI hit-test dispatch: EditorFontMagnifier, a local NSEvent monitor for .magnify events (installed once in SourceEditorView.makeNSView) that runs before normal event dispatch for every pinch anywhere in the window, and used to decide "is this over the editor" with scroll.bounds.contains(scroll.convert(event.locationInWindow, from: nil)) — a hand-rolled frame snapshot. Since the overhaul moved the editor and preview from one SwiftUI view tree under a single hosting view to separate NSHostingControllers under one NSSplitViewController (WorkspaceSplit.swift), that snapshot is one more place that can disagree with the window's actual current layout (e.g. mid split-view layout pass), and getting it wrong meant silently swallowing a pinch meant for the preview: the monitor returns nil, and nothing else — including the preview's own MagnificationGesture — ever sees the event.

Fix. EditorFontMagnifier.targets(_:_:) now asks AppKit for the actual view under the pointer (window.contentView?.hitTest(event.locationInWindow)) and checks whether it is a descendant of the editor's scroll view, instead of re-deriving the answer from a captured frame. hitTest is always authoritative for the current layout, so it cannot go stale the way a snapshot can.

Honesty about verification: I could not verify this against a live trackpad — there is no interactive macOS GUI session reachable from this (Linux) environment. This is a reasoned fix from static analysis of the only event-monitor-based (bypass-normal-dispatch) mechanism touching magnify events anywhere in the app, not a fix confirmed by feel. That caveat is also in the commit message itself so it survives history, not just this PR description. If pinch is still off after this lands, the next thing to check live is whether NSScrollView.allowsMagnification got enabled somewhere on the preview's own ScrollView, which would make the scroll view itself consume the gesture before SwiftUI's MagnificationGesture sees it.

Testing

EditorFontMagnifier.targets is extracted from the previously-opaque install closure so it is directly testable. New ZoomTests.testEditorFontMagnifierTargetsOnlyTheEditorsOwnScrollView hosts two side-by-side views (mirroring the split-view shape: the editor's scroll view and a sibling "preview" pane, not nested) and asserts a synthetic event over each side routes correctly, plus the no-window/different-window cases. AppKit has no public constructor for a real .magnify-typed NSEvent, so the synthetic event is built with NSEvent.keyEvent(with:...) (the same factory EditorFirstFocusTests already uses to synthesize keyboard events) — targets only reads .window/.locationInWindow, both of which this factory sets correctly regardless of the nominal event type.

Full Mac gate (build + swift test) run on [email protected] under the shared fleet lock, against real release Rust binaries — result reported in a follow-up comment once the queued run completes (queue was held by another agent's run at request time).

🤖 Generated with Claude Code

…ont-size magnifier

Owner: pinch-to-zoom on the preview used to work and no longer does (or
works badly).

Investigation: PreviewZoom.swift's PreviewMagnify/MagnificationGesture on
the preview itself is byte-for-byte unchanged since before the appearance
overhaul (#653/#666) — `git diff` against the pre-overhaul commit on this
file is empty — so the regression is not a code change to the gesture
itself. Nothing else about ordinary preview interaction (clicks,
navigation) was reported broken, which points at the one thing in this
area that is *not* part of normal SwiftUI hit-test dispatch:
EditorFontMagnifier, a *local NSEvent monitor* for `.magnify` events
(installed once in SourceEditorView.makeNSView) that runs before normal
event dispatch for every pinch in the window, and used to decide "is this
over the editor" with `scroll.bounds.contains(scroll.convert(event.locationInWindow,
from: nil))` — a hand-rolled frame snapshot. Since the overhaul moved the
editor and preview from one SwiftUI view tree under a single hosting view
to separate NSHostingControllers under one NSSplitViewController
(WorkspaceSplit.swift), that snapshot is one more place that can disagree
with the window's actual current layout (e.g. mid split-view layout
pass), and getting it wrong meant silently swallowing a pinch meant for
the preview: the monitor returns `nil`, and nothing else — including the
preview's own MagnificationGesture — ever sees the event.

Fix: `EditorFontMagnifier.targets(_:_:)` now asks AppKit for the actual
view under the pointer (`window.contentView?.hitTest(event.locationInWindow)`)
and checks whether it is a descendant of the editor's scroll view, instead
of re-deriving the answer from a captured frame. hitTest is always
authoritative for the current layout, so it cannot go stale the way a
snapshot can.

## Testing

`EditorFontMagnifier.targets` is extracted from the previously-opaque
`install` closure so it is directly testable. New
ZoomTests.testEditorFontMagnifierTargetsOnlyTheEditorsOwnScrollView hosts
two side-by-side views (mirroring the split-view shape: the editor's
scroll view and a sibling "preview" pane, not nested) and asserts a
synthetic event over each side routes correctly, plus the
no-window/different-window cases. AppKit has no public constructor for a
real `.magnify`-typed NSEvent, so the synthetic event is built with
`NSEvent.keyEvent(with:...)` (the same factory `EditorFirstFocusTests`
already uses to synthesize keyboard events) — `targets` only reads
`.window`/`.locationInWindow`, both of which this factory sets correctly
regardless of the nominal event type.

I could not verify the fix against a live trackpad (no interactive macOS
GUI session from this environment) — full Mac gate (build + swift test)
results are in the PR body; if pinch is still off after this lands, the
next thing to check live is whether NSScrollView.allowsMagnification got
enabled somewhere on the preview's own ScrollView, which would make the
scroll view itself consume the gesture before SwiftUI's MagnificationGesture
sees it.
@GoKubar
GoKubar marked this pull request as ready for review September 16, 2026 02:28
@GoKubar
GoKubar merged commit 336e8f0 into main Sep 16, 2026
20 of 21 checks passed
@GoKubar
GoKubar deleted the agent/claude/fix-preview-pinch-zoom branch September 16, 2026 04:17
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.

1 participant