Repository navigation
Chrome-style live sidebar reorder: rows animate on mousemove, groups drag as blocks #8467
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 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
86cd5cf
Live Chrome-style sidebar reorder preview in the AppKit table
lawrencecchen 14d46d9
Address review: block-move planner, live target refresh, action-deriv…
lawrencecchen ed66997
Localize the floating-row +N badge (en/ja)
lawrencecchen 709b718
Dogfood round 2: drag-back restore, mousedown activation, member-widt…
lawrencecchen dd85801
Fix preview oscillation: keep the slot while the pointer rides the dr…
lawrencecchen 31864d8
Dogfood round 4: block-center thresholds, sticky group boundaries, dr…
lawrencecchen c8d0edc
Make local sidebar drags follow block geometry beyond the sidebar
lawrencecchen da11cd3
Merge remote-tracking branch 'origin/main' into task-sidebar-fluid-re…
lawrencecchen 39c130a
Add failing XCUITests for sidebar reorder gestures
lawrencecchen 7984b9c
Rebuild local reorder around immutable drag state
lawrencecchen 07c1b61
Add failing lifecycle tests for direct sidebar reorder
lawrencecchen d41590f
Add slow held XCU drag coverage
lawrencecchen 7181db6
Use direct pointer tracking for sidebar reorder
lawrencecchen df2bb0a
Stabilize sidebar reorder XCU fixture
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
162 changes: 162 additions & 0 deletions
162
...dation/Sources/CmuxFoundation/SidebarDrop/SidebarWorkspaceReorderPreviewPermutation.swift
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,162 @@ | ||
| public import Foundation | ||
|
|
||
| /// One visible sidebar row as seen by the live-reorder preview. | ||
| public struct SidebarWorkspaceReorderPreviewRow: Equatable, Sendable { | ||
| public let workspaceId: UUID | ||
| public let groupId: UUID? | ||
| public let isGroupHeader: Bool | ||
|
|
||
| public init(workspaceId: UUID, groupId: UUID?, isGroupHeader: Bool) { | ||
| self.workspaceId = workspaceId | ||
| self.groupId = groupId | ||
| self.isGroupHeader = isGroupHeader | ||
| } | ||
| } | ||
|
|
||
| /// The row order the sidebar should show while a drag hovers a resolved plan, | ||
| /// expressed as source indices into the input rows. | ||
| public struct SidebarWorkspaceReorderPreviewOrder: Equatable, Sendable { | ||
| /// Indices into the input rows, in the order the preview should display. | ||
| public let order: [Int] | ||
|
|
||
| /// Indices into the input rows forming the dragged block (header first | ||
| /// for group drags, single element for workspace drags). | ||
| public let draggedBlock: [Int] | ||
|
|
||
| /// The group the dragged workspace would join when dropped here, `nil` | ||
| /// for a top-level slot. Drives the floating row's indent preview. | ||
| public let destinationGroupId: UUID? | ||
| } | ||
|
|
||
| /// Maps a resolved drop plan's indicator onto a concrete visible row order so | ||
| /// the table can animate rows apart while the drag is still in flight. The | ||
| /// commit stays plan-driven; this only decides what the preview shows, and it | ||
| /// is derived from the same indicator the resolver would render, so the | ||
| /// settled preview and the committed order agree. | ||
| public struct SidebarWorkspaceReorderPreviewPermutation: Sendable { | ||
| public init() {} | ||
|
|
||
| /// Resolves the preview order for a plan, or `nil` when the indicator | ||
| /// cannot be mapped onto the visible rows (the caller should keep the | ||
| /// last valid preview). | ||
| public func previewOrder( | ||
| rows: [SidebarWorkspaceReorderPreviewRow], | ||
| draggedWorkspaceId: UUID, | ||
| indicator: SidebarDropIndicator, | ||
| scope: SidebarWorkspaceReorderDropIndicatorScope | ||
| ) -> SidebarWorkspaceReorderPreviewOrder? { | ||
| guard let block = draggedBlockIndices(rows: rows, draggedWorkspaceId: draggedWorkspaceId), | ||
| !block.isEmpty else { | ||
| return nil | ||
| } | ||
| // An indicator pointing at the dragged block itself is a no-op slot. | ||
| if let tabId = indicator.tabId, block.contains(where: { rows[$0].workspaceId == tabId }) { | ||
| return SidebarWorkspaceReorderPreviewOrder( | ||
| order: Array(rows.indices), | ||
| draggedBlock: block, | ||
| destinationGroupId: destinationGroupId(scope: scope) | ||
| ) | ||
| } | ||
|
|
||
| let blockSet = Set(block) | ||
| let remaining = rows.indices.filter { !blockSet.contains($0) } | ||
| guard let insertionOffset = insertionOffset( | ||
| rows: rows, | ||
| remaining: remaining, | ||
| indicator: indicator, | ||
| scope: scope | ||
| ) else { | ||
| return nil | ||
| } | ||
|
|
||
| var order: [Int] = [] | ||
| order.reserveCapacity(rows.count) | ||
| order.append(contentsOf: remaining.prefix(insertionOffset)) | ||
| order.append(contentsOf: block) | ||
| order.append(contentsOf: remaining.dropFirst(insertionOffset)) | ||
| return SidebarWorkspaceReorderPreviewOrder( | ||
| order: order, | ||
| draggedBlock: block, | ||
| destinationGroupId: destinationGroupId(scope: scope) | ||
| ) | ||
| } | ||
|
|
||
| /// The dragged rows as one unit: a workspace row alone, or a group header | ||
| /// plus its contiguous member rows when the dragged id is a group anchor. | ||
| private func draggedBlockIndices( | ||
| rows: [SidebarWorkspaceReorderPreviewRow], | ||
| draggedWorkspaceId: UUID | ||
| ) -> [Int]? { | ||
| if let headerIndex = rows.firstIndex(where: { $0.isGroupHeader && $0.workspaceId == draggedWorkspaceId }) { | ||
| let groupId = rows[headerIndex].groupId | ||
| var block = [headerIndex] | ||
| var next = headerIndex + 1 | ||
| while next < rows.count, !rows[next].isGroupHeader, rows[next].groupId == groupId, groupId != nil { | ||
| block.append(next) | ||
| next += 1 | ||
| } | ||
| return block | ||
| } | ||
| guard let rowIndex = rows.firstIndex(where: { !$0.isGroupHeader && $0.workspaceId == draggedWorkspaceId }) else { | ||
| return nil | ||
| } | ||
| return [rowIndex] | ||
| } | ||
|
|
||
| /// Where in the remaining (block-removed) rows the block re-inserts. | ||
| private func insertionOffset( | ||
| rows: [SidebarWorkspaceReorderPreviewRow], | ||
| remaining: [Int], | ||
| indicator: SidebarDropIndicator, | ||
| scope: SidebarWorkspaceReorderDropIndicatorScope | ||
| ) -> Int? { | ||
| guard let tabId = indicator.tabId else { | ||
| return remaining.count | ||
| } | ||
| if case .group(let groupId) = scope { | ||
| // Group scope: the indicator names a member row (or the anchor | ||
| // when the slot is directly below a header). Insert against that | ||
| // row's edge inside the group span. | ||
| if let memberOffset = remaining.firstIndex(where: { index in | ||
| let row = rows[index] | ||
| return !row.isGroupHeader && row.groupId == groupId && row.workspaceId == tabId | ||
| }) { | ||
| return indicator.edge == .top ? memberOffset : memberOffset + 1 | ||
| } | ||
| if let headerOffset = remaining.firstIndex(where: { index in | ||
| let row = rows[index] | ||
| return row.isGroupHeader && row.groupId == groupId | ||
| }) { | ||
| return headerOffset + 1 | ||
| } | ||
| return nil | ||
| } | ||
| // Top-level/raw scope: the indicator names a top-level row. When that | ||
| // row is a group header (anchor id), a bottom edge means below the | ||
| // whole group block, not between the header and its first member. | ||
| guard let targetOffset = remaining.firstIndex(where: { rows[$0].workspaceId == tabId }) else { | ||
| return nil | ||
| } | ||
| if indicator.edge == .top { | ||
| return targetOffset | ||
| } | ||
| let targetRow = rows[remaining[targetOffset]] | ||
| guard targetRow.isGroupHeader, let groupId = targetRow.groupId else { | ||
| return targetOffset + 1 | ||
| } | ||
| var offset = targetOffset + 1 | ||
| while offset < remaining.count { | ||
| let row = rows[remaining[offset]] | ||
| if row.isGroupHeader || row.groupId != groupId { break } | ||
| offset += 1 | ||
| } | ||
| return offset | ||
| } | ||
|
|
||
| private func destinationGroupId( | ||
| scope: SidebarWorkspaceReorderDropIndicatorScope | ||
| ) -> UUID? { | ||
| guard case .group(let groupId) = scope else { return nil } | ||
| return groupId | ||
| } | ||
| } | ||
170 changes: 170 additions & 0 deletions
170
...Foundation/Tests/CmuxFoundationTests/SidebarWorkspaceReorderPreviewPermutationTests.swift
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,170 @@ | ||
| import Foundation | ||
| import Testing | ||
| @testable import CmuxFoundation | ||
|
|
||
| @Suite struct SidebarWorkspaceReorderPreviewPermutationTests { | ||
| private let a = UUID() | ||
| private let b = UUID() | ||
| private let c = UUID() | ||
| private let d = UUID() | ||
| private let groupAnchor = UUID() | ||
| private let member1 = UUID() | ||
| private let member2 = UUID() | ||
| private let groupId = UUID() | ||
|
|
||
| private func row(_ id: UUID, group: UUID? = nil, header: Bool = false) -> SidebarWorkspaceReorderPreviewRow { | ||
| SidebarWorkspaceReorderPreviewRow(workspaceId: id, groupId: group, isGroupHeader: header) | ||
| } | ||
|
|
||
| /// a b c d, drag a below c → b c a d | ||
| @Test func movesWorkspaceBelowTarget() throws { | ||
| let rows = [row(a), row(b), row(c), row(d)] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: a, | ||
| indicator: SidebarDropIndicator(tabId: c, edge: .bottom), | ||
| scope: .raw | ||
| )) | ||
| #expect(preview.order == [1, 2, 0, 3]) | ||
| #expect(preview.draggedBlock == [0]) | ||
| #expect(preview.destinationGroupId == nil) | ||
| } | ||
|
|
||
| /// a b c d, drag d above b → a d b c | ||
| @Test func movesWorkspaceAboveTarget() throws { | ||
| let rows = [row(a), row(b), row(c), row(d)] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: d, | ||
| indicator: SidebarDropIndicator(tabId: b, edge: .top), | ||
| scope: .raw | ||
| )) | ||
| #expect(preview.order == [0, 3, 1, 2]) | ||
| } | ||
|
|
||
| /// nil tabId inserts at the end of the list. | ||
| @Test func nilTargetAppendsAtEnd() throws { | ||
| let rows = [row(a), row(b), row(c)] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: a, | ||
| indicator: SidebarDropIndicator(tabId: nil, edge: .bottom), | ||
| scope: .raw | ||
| )) | ||
| #expect(preview.order == [1, 2, 0]) | ||
| } | ||
|
|
||
| /// An indicator that points at the dragged row itself keeps the order. | ||
| @Test func selfTargetIsIdentity() throws { | ||
| let rows = [row(a), row(b), row(c)] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: b, | ||
| indicator: SidebarDropIndicator(tabId: b, edge: .top), | ||
| scope: .raw | ||
| )) | ||
| #expect(preview.order == [0, 1, 2]) | ||
| } | ||
|
|
||
| /// Dragging a group anchor picks up the header and its contiguous member | ||
| /// rows as one block. | ||
| @Test func anchorDragMovesWholeBlock() throws { | ||
| let rows = [ | ||
| row(a), | ||
| row(groupAnchor, group: groupId, header: true), | ||
| row(member1, group: groupId), | ||
| row(member2, group: groupId), | ||
| row(b), | ||
| ] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: groupAnchor, | ||
| indicator: SidebarDropIndicator(tabId: b, edge: .bottom), | ||
| scope: .topLevel | ||
| )) | ||
| #expect(preview.draggedBlock == [1, 2, 3]) | ||
| #expect(preview.order == [0, 4, 1, 2, 3]) | ||
| } | ||
|
|
||
| /// Top-level scope: a bottom edge against a group header lands below the | ||
| /// whole expanded group, not between the header and its first member. | ||
| @Test func bottomOfHeaderSkipsGroupMembers() throws { | ||
| let rows = [ | ||
| row(a), | ||
| row(groupAnchor, group: groupId, header: true), | ||
| row(member1, group: groupId), | ||
| row(member2, group: groupId), | ||
| row(b), | ||
| ] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: a, | ||
| indicator: SidebarDropIndicator(tabId: groupAnchor, edge: .bottom), | ||
| scope: .topLevel | ||
| )) | ||
| #expect(preview.order == [1, 2, 3, 0, 4]) | ||
| #expect(preview.destinationGroupId == nil) | ||
| } | ||
|
|
||
| /// Group scope: inserting below a member row joins the group and reports | ||
| /// the destination group for the indent preview. | ||
| @Test func groupScopeInsertsAmongMembers() throws { | ||
| let rows = [ | ||
| row(a), | ||
| row(groupAnchor, group: groupId, header: true), | ||
| row(member1, group: groupId), | ||
| row(member2, group: groupId), | ||
| row(b), | ||
| ] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: a, | ||
| indicator: SidebarDropIndicator(tabId: member1, edge: .bottom), | ||
| scope: .group(groupId) | ||
| )) | ||
| #expect(preview.order == [1, 2, 0, 3, 4]) | ||
| #expect(preview.destinationGroupId == groupId) | ||
| } | ||
|
|
||
| /// Group scope with the anchor as target (slot directly below a header, | ||
| /// e.g. a collapsed group) inserts right after the header row. | ||
| @Test func groupScopeAnchorTargetInsertsBelowHeader() throws { | ||
| let rows = [ | ||
| row(a), | ||
| row(groupAnchor, group: groupId, header: true), | ||
| row(b), | ||
| ] | ||
| let preview = try #require(SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: a, | ||
| indicator: SidebarDropIndicator(tabId: groupAnchor, edge: .bottom), | ||
| scope: .group(groupId) | ||
| )) | ||
| #expect(preview.order == [1, 0, 2]) | ||
| #expect(preview.destinationGroupId == groupId) | ||
| } | ||
|
|
||
| /// Unknown indicator target refuses (caller keeps the last preview). | ||
| @Test func unknownTargetReturnsNil() { | ||
| let rows = [row(a), row(b)] | ||
| let preview = SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: a, | ||
| indicator: SidebarDropIndicator(tabId: UUID(), edge: .top), | ||
| scope: .raw | ||
| ) | ||
| #expect(preview == nil) | ||
| } | ||
|
|
||
| /// Dragged id missing from the rows refuses. | ||
| @Test func missingDraggedRowReturnsNil() { | ||
| let rows = [row(a), row(b)] | ||
| let preview = SidebarWorkspaceReorderPreviewPermutation().previewOrder( | ||
| rows: rows, | ||
| draggedWorkspaceId: UUID(), | ||
| indicator: SidebarDropIndicator(tabId: a, edge: .top), | ||
| scope: .raw | ||
| ) | ||
| #expect(preview == 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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indicatorScopedescribes where to render the indicator, not necessarily whether the workspace will join that group: the resolver has root-lane group-boundary plans that render with.group(...)while committingusesTopLevelRows: truewithexplicitGroupId == nil. Returning the scope's group here makes the floating row indent as if it will become a group member even though the drop commits a top-level move, so root drops around expanded/collapsed groups preview the wrong hierarchy. Please derive this from the reorder action's explicit destination group instead of the render scope.Useful? React with 👍 / 👎.