Repository navigation
fix(toolbar): Let a drag that starts on a chip move the bar - #132
Conversation
On macOS 27, SwiftUI's NSHostingView cuts every part of the view it draws out of the window's drag region, so isMovableByWindowBackground only moves the bar from its transparent edge and the gaps between segments. mouseDownCanMoveWindow still returns true at every chip point; the change is in the region SwiftUI reports, and it covers plain Text and glass as well as buttons. When the pointer slides along a bar that is not following it, end the chip's press while the drag flag refuses its action, then hand the rest of the gesture to performDrag. A bar AppKit is already carrying keeps the pointer on the same spot, so macOS 26 keeps its native drag. Both drag paths go through one injectable dragger so tests can stand in for the window server. Fixes #129
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Relative drag detection Annotate/ToolbarPanel.swift, AnnotateTests/ToolbarTests.swift |
ToolbarPanel checks pointer movement relative to the bar against the existing drag threshold. Tests cover stationary and moving bars, and verify that movement without an active press does not trigger a slide. |
Chip drag handoff and gesture lifecycle Annotate/ToolbarPanel.swift, AnnotateTests/ToolbarTests.swift |
ToolbarPanel sends a synthetic mouse-up to a chip before starting a window drag with the original press. It starts the drag once per press and polls for primary-button release. Tests cover click behavior, threshold-crossing drags, both layouts, color-picker suppression, position persistence, and release handling. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- epilande/Annotate#129: Describes chip-originated drags that do not move the toolbar; this change adds a window-drag handoff for chip presses.
Possibly related PRs
- epilande/Annotate#128: Adds the horizontal and vertical toolbar layouts that this change supports in its chip-drag handling and tests.
Suggested reviewers: usame-cetinkaya
Merge Risk: 
Minimal · up to 31657
-
No confirmed issue remains that should block merging. The reported macOS 27 behavior has been manually checked; macOS 26 edge-pinned behavior remains unchecked.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
Issue [
#129] requires chip-originated drags to move the toolbar without selecting a tool or opening the color picker.ToolbarPaneldetects travel pastToolbarPress.dragThreshold, suppresses the chip action, and starts the injectable window drag with the original mouse-down. Release polling closes the gesture when AppKit consumes mouse-up.ToolbarTestscovers horizontal and vertical tool-chip drags, color-chip picker suppression, click behavior, and position persistence.
Full details: Out of Scope Changes check
-
Explanation
The changes are limited to toolbar drag handling and automated tests for issue [
#129]. The injectable dragger and release-state tests support deterministic coverage of the required AppKit behavior. No unrelated product change is demonstrated.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 2 files.
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
performDrag(with:) wants the original mouse-down, so the chip path now keeps the press's mouse-down and hands that over instead of the drag event that crossed the threshold. performDrag also returns right away and may never send the mouse-up. When the button is still down after the hand-off, poll it and close the gesture once it is released, saving where the bar landed, whether or not a mouse-up reaches the panel. A mouse-up that does arrive, or the next press, stops the poll.
Live verificationHead: 316576b
Not tested:
The clips show the fix on top or left and compare-h-fix132-top-main-bottom-public.mp4compare-v-fix132-left-main-right-public.mp4 |
On macOS 27.2, NSWindow.performDrag(with:) no longer moves the toolbar panel. It returns right away and logs "Window move completed without beginning", so neither a drag from a chip nor one from the bar background moved the bar. 59fd934 (#132) fails the same way on 27.2, so no later commit caused this. The panel now tracks the press in sendEvent and places itself from the press origin plus pointer travel, clamped to the overlay. Native window moves are turned off so a press is never moved twice. A chip press is still released, without firing, once the drag crosses the threshold. Hiding the bar mid-drag closes the gesture and saves where it landed. The new tests send real pointer events with no stand-in mover, from a chip and from the bar background, in both layouts.


Overview
Lets you drag the floating toolbar from any tool or color chip again on macOS 27, without changing the tool or opening a picker.
Fixes #129
Motivation
On macOS 27, pressing a chip and dragging left the bar where it was. Only the thin edge and the gaps between segments moved it. On macOS 26 the bar followed the pointer from anywhere, as #89 intended. The drag code hasn't changed since #89.
The cause is a change in how SwiftUI reports the window's drag region on macOS 27.
NSHostingViewnow cuts every part of the view it draws out of that region, soisMovableByWindowBackgroundonly works from the transparent edge and the gaps.mouseDownCanMoveWindowstill returns true at every chip point. The change also covers plainTextand glass, not just buttons.Changes
Toolbar
performDrag. A bar that AppKit is already carrying keeps the pointer on the same spot, so macOS 26 keeps its native drag. Both drag paths go through one injectable dragger, so tests can stand in for the window server.Tests
testADragThatStartsOnAToolChipMovesTheBarandtestADragThatStartsOnAToolChipMovesTheColumncover the horizontal and vertical layouts.testADragThatStartsOnTheColorChipMovesTheBarWithoutOpeningThePickercovers the color chip.testThePointerSlidesAlongABarThatStandsStill,testThePointerStaysPutOnABarThatFollowsIt, andtestNoPressMeansNoSlidecover how a stuck bar is detected.Screenshots
Before and after clips are in the Live verification comment.
Breaking Changes
None
Testing
mainand pass with the fixswift test: 839 tests, 0 failuresSummary by CodeRabbit