Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Picked tabs dragged to another space all move, on its icon or in its list (#128)

Victor Kildahl85d8b2bc10d9
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index 1fe5fc0..21dcd25 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -964,23 +964,30 @@ final class SidebarStore {
/// `following`: the window that goes along to `sid`.
func moveTab(_ id: UUID, toSpace sid: UUID, following: UUID? = nil) {
- guard let space = spaces[sid], let it = items[id] else { return }
- let from = spaceID(ofItem: id)
- let moved = Set([id] + it.children)
- let list = isPinned(id) ? [] : (from.flatMap { spaces[$0] }.map { shownTabs(under: $0.todayContainerID) } ?? [])
- if isFavorite(id) {
- moveItem(id, to: space.favoritesContainerID, index: nil)
- } else {
- let pinned = isPinned(id)
- moveItem(id, to: pinned ? space.pinnedContainerID : space.todayContainerID, index: pinned ? nil : 0)
- }
+ moveTabs([id], toSpace: sid, following: following)
+ }
+
+ /// Items of one space, in sidebar order, moved together (picked tabs dropped on a space):
+ /// favorites and pinned tabs join the end of their section, Today tabs lead the new Today,
+ /// each keeping its order.
+ func moveTabs(_ ids: [UUID], toSpace sid: UUID, following: UUID? = nil) {
+ let ids = ids.filter { items[$0] != nil }
+ guard let space = spaces[sid], let first = ids.first else { return }
+ let from = spaceID(ofItem: first)
+ let moved = Set(ids + ids.flatMap { items[$0]?.children ?? [] })
+ let today = from.flatMap { spaces[$0] }.map { shownTabs(under: $0.todayContainerID) } ?? []
+ let favorites = ids.filter { isFavorite($0) }
+ let pinned = ids.filter { !isFavorite($0) && isPinned($0) }
+ moveItems(favorites, to: space.favoritesContainerID, index: nil)
+ moveItems(pinned, to: space.pinnedContainerID, index: nil)
+ moveItems(ids.filter { !favorites.contains($0) && !pinned.contains($0) }, to: space.todayContainerID, index: 0)
// The window that goes along leaves nothing selected in the old space (Arc 1.171, Move to
// Today in <space>); another window that had it open there picks the next tab, as on close.
- guard let from, from != sid, spaceID(ofItem: id) == sid else { return }
+ guard let from, from != sid, spaceID(ofItem: first) == sid else { return }
for w in prefs.windows {
guard let sel = w.selectedTabPerSpace[from], moved.contains(sel) else { continue }
- let next = w.id == following ? nil
- : closeSuccessor(of: sel, in: from, window: w.id, list: list.filter { $0 == sel || !moved.contains($0) })
+ let list = today.contains(sel) ? today.filter { $0 == sel || !moved.contains($0) } : []
+ let next = w.id == following ? nil : closeSuccessor(of: sel, in: from, window: w.id, list: list)
updateWindow(w.id) { $0.selectedTabPerSpace[from] = next }
if let next, w.focusedSpaceID == from { noteShown(next) }
}
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
index 4793faf..99a789b 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
@@ -60,7 +60,8 @@ final class SidebarView: NSView {
}
let paletteChanged = lastSpaceID == nil || space.theme != store.space(lastSpaceID ?? space.id)?.theme || space.id != lastSpaceID
if space.id != lastSpaceID {
- if lastSpaceID != nil { ui.clearPicks() }
+ // A drag that hovered another space's icon carries the picks there; its end clears them.
+ if lastSpaceID != nil, ui.draggingID == nil { ui.clearPicks() }
lastSpaceID = space.id
}
if paletteChanged || palette.isDark != space.theme.palette.isDark {
@@ -920,7 +921,9 @@ final class SpaceCellView: NSView, ArcTooltipTarget {
override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
targeted = false
guard let id = draggedID(sender) else { return false }
- store.moveTab(id, toSpace: spaceID)
+ // A picked tab takes the other picks along, as a drop in the list does.
+ store.moveTabs(ui.group(for: id, in: store), toSpace: spaceID)
+ if store.focusedSpaceID(window: ui.windowID) != spaceID { ui.clearPicks() }
return true
}
diff --git a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
index 5e08a91..b02ec4c 100644
--- a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
@@ -872,6 +872,8 @@ final class SpaceListView: NSView, NSDraggingSource {
func draggingSession(_ session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {
autoscroller.stop()
ui.draggingID = nil
+ // The drag switched spaces; picks don't outlive leaving their space.
+ if store.focusedSpaceID(window: ui.windowID) != spaceID { ui.clearPicks() }
if ui.listDrop != nil { ui.listDrop = nil }
}
diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swift
index b9f4664..2ae1c35 100644
--- a/Sources/Cra/UI/SidebarUIState.swift
+++ b/Sources/Cra/UI/SidebarUIState.swift
@@ -140,9 +140,11 @@ final class SidebarUIState {
/// The tabs an action on this row moves: every picked tab, in sidebar
/// order, when the row is one of several picks; otherwise just the row.
+ /// The row's own space, since a drag can switch spaces on the way to its drop.
func group(for id: UUID, in store: SidebarStore) -> [UUID] {
guard multiSelection.count > 1, multiSelection.contains(id) else { return [id] }
- return store.listedTabIDs(in: store.focusedSpaceID(window: windowID)).filter { multiSelection.contains($0) }
+ let space = store.spaceID(ofItem: id) ?? store.focusedSpaceID(window: windowID)
+ return store.listedTabIDs(in: space).filter { multiSelection.contains($0) }
}
func clearPicks(anchor: UUID? = nil) {
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index 6d4b5ad..1492fdd 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -388,6 +388,23 @@ enum StoreTests {
expect(store.focusedSpaceID == home && store.selectedTabID(in: home) != right.id,
"a move that doesn't follow (a drop on a space) opens another tab in the space it left")
+ // Picked tabs dropped on a space go together, each section keeping their order.
+ let p1 = store.createTab(url: "https://example.com/p1", pinned: true, select: false)
+ let p2 = store.createTab(url: "https://example.com/p2", pinned: true, select: false)
+ let t1 = store.createTab(url: "https://example.com/t1", select: false)
+ let t2 = store.createTab(url: "https://example.com/t2", select: false)
+ let t3 = store.createTab(url: "https://example.com/t3")
+ let picks = store.listedTabIDs(in: home).filter { [p1.id, p2.id, t1.id, t2.id, t3.id].contains($0) }
+ let todayOrder = picks.filter { !store.isPinned($0) }
+ store.moveTabs(picks, toSpace: work)
+ expect(picks.allSatisfy { store.spaceID(ofItem: $0) == work }, "every picked tab moves to the space")
+ expect(Array(store.children(of: store.space(work)!.todayContainerID).map(\.id).prefix(3)) == todayOrder,
+ "Today tabs lead its Today in their order")
+ expect(Array(store.children(of: store.space(work)!.pinnedContainerID).map(\.id).suffix(2)) == [p1.id, p2.id],
+ "pinned tabs stay pinned, in their order")
+ expect(store.focusedSpaceID == home && store.selectedTabID(in: home).map { !picks.contains($0) } ?? true,
+ "the window stays, with none of the moved tabs open")
+
let incognito = store.addIncognitoWindow(frame: nil)
let secret = store.createTab(url: "https://example.com/secret", window: incognito.id)
expect(!store.moveTabAndFollow(secret.id, toSpace: home, window: incognito.id)