Repository navigation
mac: preview pinch-to-zoom no longer swallowed by the editor's font-size magnifier - #674
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Owner: pinch-to-zoom on the preview used to work and no longer does (or works badly).
Investigation.
PreviewZoom.swift'sPreviewMagnify/MagnificationGestureon the preview itself is byte-for-byte unchanged since before the appearance overhaul (#653/#666) —git diffagainst 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.magnifyevents (installed once inSourceEditorView.makeNSView) that runs before normal event dispatch for every pinch anywhere in the window, and used to decide "is this over the editor" withscroll.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 separateNSHostingControllers under oneNSSplitViewController(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 returnsnil, and nothing else — including the preview's ownMagnificationGesture— 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.hitTestis 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.allowsMagnificationgot enabled somewhere on the preview's ownScrollView, which would make the scroll view itself consume the gesture before SwiftUI'sMagnificationGesturesees it.Testing
EditorFontMagnifier.targetsis extracted from the previously-opaqueinstallclosure so it is directly testable. NewZoomTests.testEditorFontMagnifierTargetsOnlyTheEditorsOwnScrollViewhosts 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-typedNSEvent, so the synthetic event is built withNSEvent.keyEvent(with:...)(the same factoryEditorFirstFocusTestsalready uses to synthesize keyboard events) —targetsonly 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