Repository navigation
iOS: native drag & drop in workspace list + create workspace in group #7384
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
410dbba
Add failing regression test: downward before-move lands one row too low
azooz2003-bit 8e06d1b
iOS: native drag & drop in workspace list + create workspace in group
azooz2003-bit 350cbd2
Add failing regression test: downward after-move lands one row too low
azooz2003-bit 2c8f014
Fix downward after-move off-by-one in workspaceReorderPlan
azooz2003-bit 92ec77e
iOS: make MobileWorkspaceDropIntentResolver a static namespace, cover…
azooz2003-bit b2d7428
workspace.move: re-query group membership after addWorkspaceToGroup
azooz2003-bit 3ade789
iOS: fix in-list drop rejection with provider-based drag/drop, header…
azooz2003-bit 32881e7
Mobile host: trim ticket workspaceID in workspace.move authorization
azooz2003-bit 89fbc7e
iOS: switch workspace list drag to native List onMove
azooz2003-bit a80b2da
iOS: group context menu parity + failure toasts for disconnected actions
azooz2003-bit 88af7ad
iOS: disambiguate workspace group drop gaps
azooz2003-bit fb7adb8
Add regression coverage for workspace create and move edge cases
azooz2003-bit 182c6b2
Fix workspace create single-flight and blank group moves
azooz2003-bit a41dab2
Keep workspace regression tests under file budget
azooz2003-bit 41aae36
Move mobile workspace move regression under budget
azooz2003-bit 4e67cec
Fix workspace create target single-flight
azooz2003-bit f6b1b57
Fix disconnected workspace create request
azooz2003-bit 772f290
Gate mobile workspace mutations by capability
azooz2003-bit 2683546
Fix group action auth compatibility
azooz2003-bit f91bd22
Align workspace mutation auth contracts
azooz2003-bit 96c9e55
Restore foreground create connection gate
azooz2003-bit 2e90144
Fix mobile workspace move ordering
azooz2003-bit df653f2
Enforce mobile workspace mutation auth scope
azooz2003-bit 7d9af09
Fix mobile group header moves and mutation auth
azooz2003-bit f9cc658
Fix mobile reorder window scope
azooz2003-bit 185b0ed
Ignore stale tickets for broad mobile RPCs
azooz2003-bit 8498bdd
Gate mobile workspace mutations by ticket scope
azooz2003-bit ddc8445
Enforce create-in-group ticket scope
azooz2003-bit 60b91ee
Fix mobile host auth test macro expansion
azooz2003-bit f59df07
Import SwiftUI for workspace drag move helpers
azooz2003-bit d6918eb
Fail closed on stale mobile workspace mutation tickets
azooz2003-bit 92f07e5
Keep mobile workspace move pending through refreshes
azooz2003-bit 9a3bae2
Satisfy mobile workspace review policies
azooz2003-bit cc25ebd
Fix mobile workspace package convention lint
azooz2003-bit ca5ba5e
Surface detail workspace action failures
azooz2003-bit 2d4de3b
Avoid duplicate workspace create errors
azooz2003-bit fee9254
Fix ticket authorization project reference
azooz2003-bit 50e1e6f
Stabilize mobile workspace UI change keys
azooz2003-bit 0651b5a
Merge remote-tracking branch 'origin/main' into feat-ios-workspace-dnd
azooz2003-bit 1fdbe26
Fix iOS title menu compiler crash
azooz2003-bit 2a1f294
Add workspace ticket authorization regression test
azooz2003-bit 36c3137
Authorize mobile workspace actions for scoped tickets
azooz2003-bit 58aaabf
Stabilize pairing retry deadline test
azooz2003-bit 862d1b0
Fix workspace ticket auth test compile and reorder gating
azooz2003-bit 8f3a563
Make workspace group pending action equatable
azooz2003-bit 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
Some comments aren't visible on the classic Files Changed page.
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
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
197 changes: 197 additions & 0 deletions
197
...muxMobileShellModel/Sources/CmuxMobileShellModel/MobileWorkspaceListItem+MoveIntent.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,197 @@ | ||
| public import Foundation | ||
|
|
||
| /// List-move helpers derived from rendered list-item snapshots. | ||
| public extension MobileWorkspaceListItem { | ||
| /// Resolves a SwiftUI `List` move into a Mac-facing workspace move intent. | ||
| /// | ||
| /// The `destination` index is the pre-removal index space reported by | ||
| /// `ForEach.onMove`. Group headers are never movable, and ambiguous/no-op | ||
| /// landings resolve to `nil`. | ||
| /// | ||
| /// - Parameters: | ||
| /// - items: The rendered workspace list snapshot backing the `List`. | ||
| /// - workspaces: The full workspace order from the Mac. | ||
| /// - groups: The group snapshots from the Mac. | ||
| /// - sourceOffsets: The moved row offsets from SwiftUI. | ||
| /// - destination: The destination offset from SwiftUI, in pre-removal space. | ||
| /// - Returns: A workspace move intent, or `nil` when the move should not fire. | ||
| static func moveIntent( | ||
| items: [MobileWorkspaceListItem], | ||
| workspaces: [MobileWorkspacePreview], | ||
| groups: [MobileWorkspaceGroupPreview], | ||
| sourceOffsets: IndexSet, | ||
| destination: Int | ||
| ) -> MobileWorkspaceMoveIntent? { | ||
| guard sourceOffsets.count == 1, | ||
| let sourceIndex = sourceOffsets.first, | ||
| items.indices.contains(sourceIndex), | ||
| case .workspace(let movedWorkspace, _) = items[sourceIndex] else { | ||
| return nil | ||
| } | ||
|
|
||
| let rawDestination = min(max(destination, items.startIndex), items.endIndex) | ||
| guard rawDestination != sourceIndex, rawDestination != sourceIndex + 1 else { | ||
| return nil | ||
| } | ||
| let adjustedDestination = sourceIndex < rawDestination ? rawDestination - 1 : rawDestination | ||
| var remainingItems = items | ||
| remainingItems.remove(at: sourceIndex) | ||
| let insertionIndex = min(max(adjustedDestination, remainingItems.startIndex), remainingItems.endIndex) | ||
|
|
||
| let knownGroupIDs = Set(groups.map(\.id)) | ||
| let currentGroupID = validGroupID(movedWorkspace.groupID, knownGroupIDs: knownGroupIDs) | ||
| let orderedWithoutMoved = workspaces.filter { $0.id != movedWorkspace.id } | ||
|
|
||
| let previousItem = insertionIndex > remainingItems.startIndex | ||
| ? remainingItems[remainingItems.index(before: insertionIndex)] | ||
| : nil | ||
| let nextItem = insertionIndex < remainingItems.endIndex | ||
| ? remainingItems[insertionIndex] | ||
| : nil | ||
|
|
||
| let proposed: MobileWorkspaceMoveIntent? | ||
| switch previousItem { | ||
| case .groupHeader(let group, _): | ||
| guard knownGroupIDs.contains(group.id) else { return nil } | ||
| proposed = MobileWorkspaceMoveIntent( | ||
| groupID: group.id, | ||
| beforeWorkspaceID: firstNonAnchorWorkspace( | ||
| in: group.id, | ||
| groups: groups, | ||
| workspaces: orderedWithoutMoved, | ||
| knownGroupIDs: knownGroupIDs | ||
| ) ?? workspaceAfterGroup( | ||
| group.id, | ||
| workspaces: orderedWithoutMoved, | ||
| knownGroupIDs: knownGroupIDs | ||
| ) | ||
| ) | ||
|
|
||
| case .workspace(let previousWorkspace, _): | ||
| let previousGroupID = validGroupID(previousWorkspace.groupID, knownGroupIDs: knownGroupIDs) | ||
| if let previousGroupID { | ||
| let beforeWorkspaceID: MobileWorkspacePreview.ID? | ||
| if case .workspace(let nextWorkspace, _) = nextItem, | ||
| validGroupID(nextWorkspace.groupID, knownGroupIDs: knownGroupIDs) == previousGroupID { | ||
| beforeWorkspaceID = nextWorkspace.id | ||
| } else { | ||
| beforeWorkspaceID = workspaceAfterGroup( | ||
| previousGroupID, | ||
| workspaces: orderedWithoutMoved, | ||
| knownGroupIDs: knownGroupIDs | ||
| ) | ||
| } | ||
| proposed = MobileWorkspaceMoveIntent( | ||
| groupID: previousGroupID, | ||
| beforeWorkspaceID: beforeWorkspaceID | ||
| ) | ||
| } else { | ||
| proposed = MobileWorkspaceMoveIntent( | ||
| groupID: nil, | ||
| beforeWorkspaceID: ungroupedBeforeWorkspaceID( | ||
| nextItem: nextItem, | ||
| workspaces: orderedWithoutMoved, | ||
| knownGroupIDs: knownGroupIDs | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| case nil: | ||
| proposed = MobileWorkspaceMoveIntent( | ||
| groupID: nil, | ||
| beforeWorkspaceID: ungroupedBeforeWorkspaceID( | ||
| nextItem: nextItem, | ||
| workspaces: orderedWithoutMoved, | ||
| knownGroupIDs: knownGroupIDs | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| guard let intent = proposed else { return nil } | ||
| guard intent.groupID != currentGroupID || changesOrder( | ||
| draggedWorkspaceID: movedWorkspace.id, | ||
| beforeWorkspaceID: intent.beforeWorkspaceID, | ||
| workspaces: workspaces | ||
| ) else { | ||
| return nil | ||
| } | ||
| return intent | ||
| } | ||
|
|
||
| private static func ungroupedBeforeWorkspaceID( | ||
| nextItem: MobileWorkspaceListItem?, | ||
| workspaces: [MobileWorkspacePreview], | ||
| knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID> | ||
| ) -> MobileWorkspacePreview.ID? { | ||
| switch nextItem { | ||
| case .workspace(let nextWorkspace, _): | ||
| return nextWorkspace.id | ||
| case .groupHeader(let nextGroup, _): | ||
| return firstWorkspace( | ||
| in: nextGroup.id, | ||
| workspaces: workspaces, | ||
| knownGroupIDs: knownGroupIDs | ||
| ) | ||
| case nil: | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| private static func validGroupID( | ||
| _ groupID: MobileWorkspaceGroupPreview.ID?, | ||
| knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID> | ||
| ) -> MobileWorkspaceGroupPreview.ID? { | ||
| guard let groupID, knownGroupIDs.contains(groupID) else { return nil } | ||
| return groupID | ||
| } | ||
|
|
||
| private static func firstWorkspace( | ||
| in groupID: MobileWorkspaceGroupPreview.ID, | ||
| workspaces: [MobileWorkspacePreview], | ||
| knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID> | ||
| ) -> MobileWorkspacePreview.ID? { | ||
| workspaces.first(where: { validGroupID($0.groupID, knownGroupIDs: knownGroupIDs) == groupID })?.id | ||
| } | ||
|
|
||
| private static func firstNonAnchorWorkspace( | ||
| in groupID: MobileWorkspaceGroupPreview.ID, | ||
| groups: [MobileWorkspaceGroupPreview], | ||
| workspaces: [MobileWorkspacePreview], | ||
| knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID> | ||
| ) -> MobileWorkspacePreview.ID? { | ||
| guard let anchorWorkspaceID = groups.first(where: { $0.id == groupID })?.anchorWorkspaceID else { | ||
| return nil | ||
| } | ||
| return workspaces.first(where: { | ||
| validGroupID($0.groupID, knownGroupIDs: knownGroupIDs) == groupID && $0.id != anchorWorkspaceID | ||
| })?.id | ||
| } | ||
|
|
||
| private static func workspaceAfterGroup( | ||
| _ groupID: MobileWorkspaceGroupPreview.ID, | ||
| workspaces: [MobileWorkspacePreview], | ||
| knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID> | ||
| ) -> MobileWorkspacePreview.ID? { | ||
| guard let lastMemberIndex = workspaces.lastIndex(where: { | ||
| validGroupID($0.groupID, knownGroupIDs: knownGroupIDs) == groupID | ||
| }) else { | ||
| return nil | ||
| } | ||
| let nextIndex = workspaces.index(after: lastMemberIndex) | ||
| guard nextIndex < workspaces.endIndex else { return nil } | ||
| return workspaces[nextIndex].id | ||
| } | ||
|
|
||
| private static func changesOrder( | ||
| draggedWorkspaceID: MobileWorkspacePreview.ID, | ||
| beforeWorkspaceID: MobileWorkspacePreview.ID?, | ||
| workspaces: [MobileWorkspacePreview] | ||
| ) -> Bool { | ||
| var ids = workspaces.map(\.id) | ||
| guard let currentIndex = ids.firstIndex(of: draggedWorkspaceID) else { return false } | ||
| ids.remove(at: currentIndex) | ||
| let targetIndex = beforeWorkspaceID.flatMap { ids.firstIndex(of: $0) } ?? ids.endIndex | ||
| ids.insert(draggedWorkspaceID, at: targetIndex) | ||
| return ids != workspaces.map(\.id) | ||
| } | ||
| } |
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.