Repository navigation
Animate sidebar workspace groups (morph, collapse, rollup) + grouping focus fixes #5779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 26 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
97a0eb3
Rebuild sidebar workspace reorder on a SwiftUI DragGesture
lawrencecchen f81905f
Keep reorder gesture host stable during drag
lawrencecchen e120bfd
Sidebar workspace group animations + rollup + focus fixes
lawrencecchen d5757a2
Sidebar drag: Escape-cancel via HID poll + remove end-of-list drop line
lawrencecchen 44910a1
Sidebar drag: animated drop gap (rows shift apart) instead of an indi…
lawrencecchen 79798c1
Sidebar drag: true live reorder (row travels through the list)
lawrencecchen 6740893
Sidebar live reorder: fix stationary-pointer oscillation
lawrencecchen dc419f0
Sidebar drag: restore fully on every non-commit end; fix review findings
lawrencecchen d6fc3f6
Move SidebarGroupAnimation into its own file
lawrencecchen 2ef6b60
Refresh Swift file length budgets for the drag-restore work
lawrencecchen c4c6513
Sidebar live reorder: let autoscroll reorder under a stationary pointer
lawrencecchen 99ca472
Sidebar drop: nil indicator over a row commits as a no-op
lawrencecchen beed2dd
Sidebar drag: capture the rollback snapshot synchronously; arm the lo…
lawrencecchen ad1f7b6
Sidebar drag: stop scroll-follow fighting the live reorder; tighter m…
lawrencecchen 534c21c
Sidebar live reorder: arm the loop-breaker on an actual order change,…
lawrencecchen 651dd4d
Sidebar live reorder: kill the animation-feedback cascade
lawrencecchen 60f2c58
Merge gesture-driven sidebar reorder (PR #5226) onto the group-animat…
lawrencecchen 003fb27
Sidebar gesture reorder: stop the drop-target gate from killing the drag
lawrencecchen d405d1b
Fix test patterns for the workspace render item's effectiveGroupId pa…
lawrencecchen 2644626
Sidebar gesture reorder: derive the cursor from translation, not loca…
lawrencecchen c8502da
Sidebar gesture reorder: clamp members to their group, drop-into head…
lawrencecchen 58e9614
Sidebar gesture reorder: animate the follower's indent across group b…
lawrencecchen 9bb0325
Sidebar gesture reorder: one-step drag into and out of groups, X axis…
lawrencecchen 796a9c4
Sidebar gesture reorder: fix the full edge-case audit (ultracode sweep)
lawrencecchen 214e22f
Sidebar gesture reorder: expand collapsed groups on join, unpin on le…
lawrencecchen 834fbfe
Sidebar gesture reorder: stacked hitboxes at group bottoms; animate f…
lawrencecchen 6efee48
Sidebar gesture reorder: actually animate the follower indent and width
lawrencecchen 3bf1196
Sidebar gesture reorder: deterministic indent animation + midpoint bo…
lawrencecchen 954d39c
Sidebar gesture reorder: animate the follower indent at its single mu…
lawrencecchen 0135770
Sidebar gesture reorder: touch-triggered slots, spring-loaded collaps…
lawrencecchen 256728d
Sidebar gesture reorder: one reference point for slot + membership, h…
lawrencecchen a831f01
Sidebar reorder: replace the direction-flag probe with a continuous c…
lawrencecchen ce61759
Sidebar: group header hover background; spring-load auto-collapses on…
lawrencecchen 615bfe7
Sidebar: highlight the whole group region (header + member rows), not…
lawrencecchen e968159
Sidebar: hovering a nested member also highlights its whole group
lawrencecchen fc4bc75
Sidebar: draw the group highlight as one backdrop behind the rows, no…
lawrencecchen ccb582b
WIP: isolated animated group backdrop + sooner last-member catch
lawrencecchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Shared animation timings for workspace-group structure changes in the | ||
| /// sidebar (promote-in-place, ungroup, collapse/expand, member join/leave, | ||
| /// drag-reorder settle). | ||
| /// | ||
| /// One source of truth so every entrypoint that mutates group structure | ||
| /// (keyboard shortcut, context menu, group-header buttons, drag-and-drop, | ||
| /// socket/CLI) animates identically. The `TabManager` group mutation methods | ||
| /// wrap their structural changes in `withAnimation(SidebarGroupAnimation.<case>)`, | ||
| /// and the sidebar rows carry `.transition(.sidebarGroupRow)` so inserted or | ||
| /// removed rows fade while their siblings reflow within the same transaction. | ||
| enum SidebarGroupAnimation { | ||
| /// Workspace row morphs into a group header (and back), member rows join or | ||
| /// leave a group, drag-reorder drops settle. | ||
| static let structure: Animation = .snappy(duration: 0.26) | ||
|
|
||
| /// Group collapse / expand: member rows slide+fade and the chevron rotates. | ||
| static let collapse: Animation = .snappy(duration: 0.24) | ||
|
|
||
| /// Mid-drag row crossing during the live reorder. Deliberately faster | ||
| /// than `structure`: the row is chasing the pointer, and a 0.26s spring | ||
| /// reads as input lag when crossings come several per second. No bounce — | ||
| /// overshoot under a moving pointer looks like jitter. | ||
| static let liveReorder: Animation = .snappy(duration: 0.15, extraBounce: 0) | ||
| } | ||
|
|
||
| extension AnyTransition { | ||
| /// Transition for a sidebar row appearing or disappearing because of a | ||
| /// group-structure change. A plain opacity fade keeps the morph between a | ||
| /// workspace row and a group header (same ForEach identity, swapped | ||
| /// `_ConditionalContent` branch) reading as a crossfade, while the | ||
| /// surrounding `withAnimation` transaction animates the list reflow so | ||
| /// collapse/expand and member join/leave feel like a slide for free. | ||
| static var sidebarGroupRow: AnyTransition { | ||
| .opacity | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import SwiftUI | ||
|
|
||
| /// The floating copy of the picked-up workspace row that tracks the cursor | ||
| /// during a gesture-driven reorder. For a group-header drag the follower | ||
| /// carries the WHOLE visible block (header + member rows) so the group reads | ||
| /// as one object traveling with the cursor. | ||
| /// | ||
| /// This is the ONLY view that reads `SidebarDragState.followerCursorY`, the | ||
| /// per-frame cursor position. Because it is a sibling overlay over the list (not | ||
| /// a row inside the `LazyVStack`/`ForEach`), its per-frame updates repaint just | ||
| /// this one view and never invalidate the list body — the property that keeps | ||
| /// the drag off the https://github.com/manaflow-ai/cmux/issues/2586 thrash path. | ||
| /// Implicit animations are disabled so the follower snaps to the cursor with | ||
| /// zero lag while the list rows animate the gap open underneath it — except the | ||
| /// group-membership indent, which animates on its own axis (see below). | ||
| struct SidebarReorderFollowerView: View { | ||
| let dragState: SidebarDragState | ||
| /// The committed render list, used to find the picked-up row's content | ||
| /// (and, for a header drag, the member rows that follow it). | ||
| let sourceItems: [SidebarWorkspaceRenderItem] | ||
| /// Spacing between the header and member rows in a group-block follower, | ||
| /// matching the list's row spacing. | ||
| let rowSpacing: CGFloat | ||
| /// Extra leading indent previewed for the dragged row at its current | ||
| /// landing slot, RELATIVE to its committed indent (positive tucking into | ||
| /// a group, negative pulling out, 0 unchanged). Derived by the parent | ||
| /// from the resolved membership, so it only changes when the resolved | ||
| /// membership does. | ||
| let previewExtraIndent: CGFloat | ||
| let rowContent: (SidebarWorkspaceRenderItem) -> AnyView | ||
|
|
||
| var body: some View { | ||
| if let draggedId = dragState.draggedTabId, | ||
| let cursorY = dragState.followerCursorY, | ||
| let frame = dragState.draggedRowFrame, | ||
| frame.width > 0, | ||
| frame.height > 0, | ||
| let itemIndex = sourceItems.firstIndex(where: { $0.representedWorkspaceId == draggedId }) { | ||
| let topY = cursorY - dragState.grabOffsetY | ||
| let blockItems = followerBlockItems(startingAt: itemIndex) | ||
| // The indent is applied INSIDE the position-tracked container, on | ||
| // its own animation keyed to the indent value: the row slides | ||
| // right and narrows when the landing slot crosses into a group | ||
| // (and back out), while Y stays glued to the cursor with | ||
| // animations disabled. The container is sized to the picked-up | ||
| // row's frame and top-aligned, so a group block overflows below | ||
| // it without disturbing the cursor anchor math. | ||
| VStack(alignment: .leading, spacing: rowSpacing) { | ||
| ForEach(blockItems, id: \.representedWorkspaceId) { item in | ||
| rowContent(item) | ||
| } | ||
| } | ||
| // Width and X are BOTH explicit functions of the previewed | ||
| // indent: tucking into a group slides the row right by the | ||
| // indent AND narrows it by the same amount (the trailing edge | ||
| // stays fixed), animated together on the indent's own axis while | ||
| // Y tracking below stays animation-free. | ||
| .frame(width: max(frame.width - previewExtraIndent, 0), height: frame.height, alignment: .topLeading) | ||
| .padding(.leading, previewExtraIndent) | ||
| .animation(.snappy(duration: 0.15, extraBounce: 0), value: previewExtraIndent) | ||
| .frame(width: frame.width, height: frame.height, alignment: .topLeading) | ||
| .position(x: frame.midX, y: topY + frame.height / 2) | ||
| .shadow(color: Color.black.opacity(0.18), radius: 11, x: 0, y: 5) | ||
| .opacity(0.97) | ||
| .allowsHitTesting(false) | ||
| .accessibilityHidden(true) | ||
| .zIndex(1000) | ||
| .transaction { transaction in | ||
| transaction.disablesAnimations = true | ||
| transaction.animation = nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// The dragged item plus, for a group header, the visible member rows | ||
| /// that follow it in the committed list (capped so enormous groups don't | ||
| /// turn the per-frame follower into a wall of rows). | ||
| private func followerBlockItems(startingAt itemIndex: Int) -> [SidebarWorkspaceRenderItem] { | ||
| let item = sourceItems[itemIndex] | ||
| guard case .groupHeader(let group, _) = item else { return [item] } | ||
| var block: [SidebarWorkspaceRenderItem] = [item] | ||
| var index = itemIndex + 1 | ||
| while index < sourceItems.count, block.count < 7 { | ||
| guard case .workspace(let workspace, _) = sourceItems[index], | ||
| workspace.groupId == group.id else { break } | ||
| block.append(sourceItems[index]) | ||
| index += 1 | ||
| } | ||
| return block | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import CoreGraphics | ||
| import Foundation | ||
|
|
||
| /// Maps a drag cursor position to a ``SidebarDropIndicator`` for the gesture | ||
| /// driven workspace reorder, with hysteresis so the gap does not flicker when | ||
| /// the cursor hovers exactly on a row's midpoint. | ||
| /// | ||
| /// Pure and self-contained so it is unit-testable without a running app: the | ||
| /// caller passes the reorder-scope rows as vertical bands (already resolved | ||
| /// from the live row frames) plus the current cursor Y, all in one coordinate | ||
| /// space. Edge/insertion/pinned-tier legality is delegated to | ||
| /// ``SidebarDropPlanner``; this type only adds hit-testing and stickiness. | ||
| enum SidebarReorderIndicatorResolver { | ||
| /// One reorder-scope item's vertical extent in list space. For a top-level | ||
| /// group drag, a band spans the group header plus all its member rows so | ||
| /// the whole group reads as one target. | ||
| struct Band: Equatable { | ||
| let id: UUID | ||
| let minY: CGFloat | ||
| let maxY: CGFloat | ||
|
|
||
| var midY: CGFloat { (minY + maxY) / 2 } | ||
| var height: CGFloat { max(maxY - minY, 0) } | ||
| } | ||
|
|
||
| /// Resolves the drop indicator for `cursorY`. | ||
| /// | ||
| /// - Parameters: | ||
| /// - cursorY: cursor Y in the same list space as the band extents. | ||
| /// - bands: reorder-scope bands in scope order, contiguous and sorted. | ||
| /// - draggedId: the workspace being dragged. | ||
| /// - pinnedIds: pinned ids within the scope (tier constraint). | ||
| /// - current: the indicator currently shown, used for hysteresis. | ||
| /// - hysteresisMargin: half-width of the dead-zone around a band midpoint | ||
| /// within which the current edge is kept (points). | ||
| /// - Returns: the indicator to show, or nil for a no-op move. | ||
| static func resolve( | ||
| cursorY: CGFloat, | ||
| bands: [Band], | ||
| draggedId: UUID, | ||
| pinnedIds: Set<UUID>, | ||
| current: SidebarDropIndicator?, | ||
| hysteresisMargin: CGFloat | ||
| ) -> SidebarDropIndicator? { | ||
| guard !bands.isEmpty else { return nil } | ||
| let scopeIds = bands.map(\.id) | ||
|
|
||
| // Below every row: append to the end of the scope. | ||
| guard let lastBand = bands.last, cursorY <= lastBand.maxY else { | ||
| return SidebarDropPlanner.indicator( | ||
| draggedTabId: draggedId, | ||
| targetTabId: nil, | ||
| tabIds: scopeIds, | ||
| pinnedTabIds: pinnedIds | ||
| ) | ||
| } | ||
|
|
||
| // First band whose bottom edge is below the cursor is the target; this | ||
| // also assigns the inter-row spacing gap to the lower band. | ||
| let targetBand = bands.first(where: { cursorY < $0.maxY }) ?? lastBand | ||
| let pointerY = cursorY - targetBand.minY | ||
|
|
||
| let effectivePointerY = stickyPointerY( | ||
| pointerY: pointerY, | ||
| band: targetBand, | ||
| scopeIds: scopeIds, | ||
| current: current, | ||
| margin: hysteresisMargin | ||
| ) | ||
|
|
||
| return SidebarDropPlanner.indicator( | ||
| draggedTabId: draggedId, | ||
| targetTabId: targetBand.id, | ||
| tabIds: scopeIds, | ||
| pinnedTabIds: pinnedIds, | ||
| pointerY: effectivePointerY, | ||
| targetHeight: targetBand.height | ||
| ) | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| /// Biases `pointerY` toward the current edge while the cursor sits within | ||
| /// `margin` of the band midpoint, so the indicator does not oscillate on | ||
| /// sub-pixel jitter at the 50% split. | ||
| private static func stickyPointerY( | ||
| pointerY: CGFloat, | ||
| band: Band, | ||
| scopeIds: [UUID], | ||
| current: SidebarDropIndicator?, | ||
| margin: CGFloat | ||
| ) -> CGFloat { | ||
| let mid = band.height / 2 | ||
| guard margin > 0, abs(pointerY - mid) < margin else { return pointerY } | ||
| guard let edge = currentEdge(for: band, scopeIds: scopeIds, current: current) else { | ||
| return pointerY | ||
| } | ||
| return edge == .top ? mid - margin : mid + margin | ||
| } | ||
|
|
||
| /// The edge of `band` that the current indicator represents, if any. The | ||
| /// planner canonicalizes "after row i" to "top of row i+1" (or the end | ||
| /// sentinel), so both forms are matched here. | ||
| private static func currentEdge( | ||
| for band: Band, | ||
| scopeIds: [UUID], | ||
| current: SidebarDropIndicator? | ||
| ) -> SidebarDropEdge? { | ||
| guard let current else { return nil } | ||
| if current.tabId == band.id, current.edge == .top { return .top } | ||
| guard let index = scopeIds.firstIndex(of: band.id) else { return nil } | ||
| let afterId: UUID? = index + 1 < scopeIds.count ? scopeIds[index + 1] : nil | ||
| if let afterId, current.tabId == afterId, current.edge == .top { return .bottom } | ||
| if afterId == nil, current.tabId == nil, current.edge == .bottom { return .bottom } | ||
| return nil | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Collects the live frames of the workspace sidebar rows (and group headers), | ||
| /// keyed by represented workspace id, in the list's `"sidebarReorderList"` | ||
| /// coordinate space. | ||
| /// | ||
| /// The gesture-driven reorder reads these via `.onPreferenceChange` to hit-test | ||
| /// the drag cursor against the rows. Resolving concrete `CGRect`s (rather than | ||
| /// `Anchor<CGRect>`) lets the value flow straight into `SidebarDragState`'s | ||
| /// non-observed geometry without a `GeometryProxy`, so the push never happens | ||
| /// inside a view-body computation. | ||
| struct SidebarReorderRowFrameKey: PreferenceKey { | ||
| static let defaultValue: [UUID: CGRect] = [:] | ||
|
|
||
| static func reduce(value: inout [UUID: CGRect], nextValue: () -> [UUID: CGRect]) { | ||
| value.merge(nextValue(), uniquingKeysWith: { _, new in new }) | ||
| } | ||
| } | ||
|
|
||
| extension View { | ||
| /// Reports this row's frame in the reorder list coordinate space under | ||
| /// `workspaceId`. | ||
| func sidebarReorderRowFrame(_ workspaceId: UUID) -> some View { | ||
| background( | ||
| GeometryReader { proxy in | ||
| Color.clear.preference( | ||
| key: SidebarReorderRowFrameKey.self, | ||
| value: [workspaceId: proxy.frame(in: .named(SidebarReorderListCoordinateSpace.name))] | ||
| ) | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| /// The named coordinate space the reorder gesture and row frames share, so the | ||
| /// gesture location and the measured row frames are guaranteed to align. | ||
| enum SidebarReorderListCoordinateSpace { | ||
| static let name = "sidebarReorderList" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.