Skip to content

fix(toolbar): Let a drag that starts on a chip move the bar - #132

Merged
epilande merged 2 commits into
mainfrom
fix/toolbar-drag-from-chip
Oct 28, 2026
Merged

epilande merged 2 commits into
mainfrom
fix/toolbar-drag-from-chip

Conversation

@epilande

@epilande epilande commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

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. NSHostingView now cuts every part of the view it draws out of that region, so isMovableByWindowBackground only works from the transparent edge and the gaps. mouseDownCanMoveWindow still returns true at every chip point. The change also covers plain Text and glass, not just buttons.

Changes

Toolbar

  • ToolbarPanel.swift - When the pointer slides along a bar that isn't following it, the chip's press ends while the drag flag blocks its action, and the rest of the gesture goes to 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

  • ToolbarTests.swift
    • testADragThatStartsOnAToolChipMovesTheBar and testADragThatStartsOnAToolChipMovesTheColumn cover the horizontal and vertical layouts.
    • testADragThatStartsOnTheColorChipMovesTheBarWithoutOpeningThePicker covers the color chip.
    • testThePointerSlidesAlongABarThatStandsStill, testThePointerStaysPutOnABarThatFollowsIt, and testNoPressMeansNoSlide cover how a stuck bar is detected.
    • The new drag tests fail without the fix, unlike the existing bookkeeping tests.

Screenshots

Before and after clips are in the Live verification comment.

Breaking Changes

None

Testing

  • New drag tests fail on main and pass with the fix
  • swift test: 839 tests, 0 failures
  • SwiftLint: 0 violations
  • Manual check on macOS 27.0.1 in both layouts: chip drags move the bar, clicks still select or open the palette, no chip stays pressed, and edge drags, relaunch position, and first click still work
  • macOS 26 with the bar pinned to an edge

Summary by CodeRabbit

  • Improvements
    • You can move the toolbar by dragging from a chip without triggering the chip’s action or opening its picker.
    • Toolbar dragging works in both horizontal and vertical layouts, and the toolbar’s position is saved after moving it.
    • Dragging also works when the window handles the gesture, and the toolbar finishes saving its position when you release the primary mouse button.

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
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 740597e1-5955-40f6-be30-3f92ac953a10
Commits

Reviewing files that changed from the base of the PR and between dab9a97 and 316576b.

Files selected for processing: 2
  • Annotate/ToolbarPanel.swift
  • AnnotateTests/ToolbarTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

ToolbarPanel now detects chip-originated drags by measuring pointer movement relative to the bar. It ends the chip press, starts a window drag with the original press, and tracks release to complete the gesture.

Changes: Toolbar chip-originated dragging

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: Normal

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: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: allowing toolbar drags that begin on a chip to move the bar.
Linked Issues check Passed Issue [#129] requires chip-originated drags to move the toolbar without selecting a tool or opening the color picker. ToolbarPanel detects travel past ToolbarPress.dragThreshold, suppresses the ch…
Out of Scope Changes check Passed 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…
Docstring Coverage Passed 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. Documentati…
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. ToolbarPanel detects travel past ToolbarPress.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. ToolbarTests covers 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.

❤️ Share

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.
@epilande

Copy link
Copy Markdown
Owner Author

Live verification

Head: 316576b
Machine: Mac mini, macOS 27.0.1, compared against main at d92640b

  • Dragging from a tool chip moves the bar without changing the tool (horizontal and vertical)
  • Dragging from the color chip moves the bar without opening the picker (horizontal and vertical)
  • Plain clicks still select a tool or open the palette
  • No chip stays pressed after a drag
  • Dragging from the edges and gaps works as before
  • The bar stays where it was left after quitting and relaunching, including after a chip drag
  • First click with Settings focused works the same as main (fix(toolbar): prevent first-click appearance change #105)
  • No extra jump when a drag starts, and the bar ends exactly under the pointer
  • Several fast chip drags in a row: no stuck press, no extra drag, and the tool doesn't change
  • Build passes, 840 tests pass, SwiftLint reports 0 violations
  • main still can't be dragged from a chip, so the bug reproduces without the fix

Not tested:

  • macOS 26, including a bar pinned to an edge of the overlay
  • Position memory on other displays
  • The exact midpoint between the tools pill and the color pill doesn't start a drag, on main too, so this PR doesn't cause it

The clips show the fix on top or left and main on the bottom or right.

compare-h-fix132-top-main-bottom-public.mp4
compare-v-fix132-left-main-right-public.mp4

Horizontal toolbar before and after dragging from the color chip

Vertical toolbar before and after dragging from the color chip

@epilande
epilande merged commit 59fd934 into main Oct 28, 2026
2 checks passed
@epilande
epilande deleted the fix/toolbar-drag-from-chip branch October 28, 2026 14:27
epilande added a commit that referenced this pull request Nov 20, 2026
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.
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.

Toolbar can't be dragged from a button on macOS 27

1 participant