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.

⌘W shows the tab shown before it if that page is still loaded, else the Today neighbour, like Arc (#105) (#121)

Victor Kildahl33ae0660cdee
diff --git a/Packages/CraCore/Sources/CraCore/CloseSuccessor.swift b/Packages/CraCore/Sources/CraCore/CloseSuccessor.swift
new file mode 100644
index 0000000..a17104d
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/CloseSuccessor.swift
@@ -0,0 +1,31 @@
+/// The tab Arc shows after the selected one closes (GitHub #105). Arc 1.171, offline copy driven
+/// through its menus, 2 Nov 2026:
+/// - It goes back to the tab shown just before, if that one still has a page: not when it was
+/// closed (a pinned tab ⌘W unloaded) or hasn't loaded since launch. Only that one tab counts;
+/// Arc doesn't walk further back, nor to the tab the closed one was opened from. "Shown just
+/// before" is per window and includes a space switch: the tab left in the other space counts,
+/// and as it's in another space, nothing goes back to it. Closing one pane of a split keeps
+/// the tab shown before the split.
+/// - Otherwise an unpinned tab hands over to its neighbour among the Today rows on screen, the one
+/// above first, loaded or not: an open folder's tabs count, a closed folder's don't. A pinned
+/// tab or favorite hands over to nothing, and so does the last tab.
+public enum CloseSuccessor {
+ /// - Parameters:
+ /// - previous: the tab shown in this window just before `closing`, if it is still in the
+ /// same space.
+ /// - hasPage: whether a tab's page is loaded.
+ /// - list: the Today tabs shown as rows, top to bottom, `closing` among them; empty for a
+ /// pinned tab.
+ public static func next<ID: Equatable>(closing: ID, previous: ID?, hasPage: (ID) -> Bool, list: [ID]) -> ID? {
+ if let previous, previous != closing, hasPage(previous) { return previous }
+ guard let i = list.firstIndex(of: closing) else { return nil }
+ if i > 0 { return list[i - 1] }
+ return i + 1 < list.count ? list[i + 1] : nil
+ }
+
+ /// A pinned tab or favorite closing (it unloads): back to the previous tab while it has a
+ /// page, else nothing. A pinned split hands over to nothing even then (Arc 1.171).
+ public static func afterPinned<ID: Equatable>(closing: ID, isSplit: Bool, previous: ID?, hasPage: (ID) -> Bool) -> ID? {
+ isSplit ? nil : next(closing: closing, previous: previous, hasPage: hasPage, list: [])
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/CloseSuccessorTests.swift b/Packages/CraCore/Tests/CraCoreTests/CloseSuccessorTests.swift
new file mode 100644
index 0000000..483dc25
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/CloseSuccessorTests.swift
@@ -0,0 +1,47 @@
+import CraCore
+import Testing
+
+/// The tab shown after a close (Arc 1.171, GitHub #105). The cases are the runs on Arc.
+struct CloseSuccessorTests {
+ // Today, top to bottom; S is pinned.
+ let today = ["C", "B", "A", "D"]
+
+ func next(_ closing: String, previous: String?, loaded: Set<String>, list: [String]? = nil) -> String? {
+ CloseSuccessor.next(closing: closing, previous: previous, hasPage: loaded.contains, list: list ?? today)
+ }
+
+ @Test func backToTheTabShownBeforeWhileItHasAPage() {
+ // A opened from S in the background, reached from D: back to D, not to S.
+ #expect(next("A", previous: "D", loaded: ["S", "D", "A"]) == "D")
+ // A pinned tab goes back the same way.
+ #expect(next("S", previous: "P2", loaded: ["S", "P2"], list: []) == "P2")
+ }
+
+ @Test func aPreviousTabWithoutAPageDoesNotCount() {
+ // Closed (a pinned tab's ⌘W) or not loaded since launch: the neighbour above instead.
+ #expect(next("D", previous: "S", loaded: ["D"]) == "A")
+ #expect(next("B", previous: "D", loaded: ["B"]) == "C")
+ // A pinned tab hands over to nothing, even with other pages loaded.
+ #expect(next("P2", previous: "S", loaded: ["P2", "C"], list: []) == nil)
+ #expect(next("S", previous: nil, loaded: ["S"], list: []) == nil)
+ }
+
+ @Test func theNeighbourAboveThenBelow() {
+ #expect(next("B", previous: nil, loaded: []) == "C")
+ #expect(next("C", previous: "B", loaded: ["C"]) == "B")
+ #expect(next("C", previous: nil, loaded: []) == "B")
+ #expect(next("D", previous: nil, loaded: []) == "A")
+ // The last tab: nothing (Arc doesn't load a pinned tab instead).
+ #expect(next("C", previous: nil, loaded: [], list: ["C"]) == nil)
+ }
+
+ @Test func aPinnedSplitHandsOverToNothing() {
+ #expect(CloseSuccessor.afterPinned(closing: "PS", isSplit: true, previous: "D", hasPage: { _ in true }) == nil)
+ #expect(CloseSuccessor.afterPinned(closing: "F1", isSplit: false, previous: "D", hasPage: { _ in true }) == "D")
+ #expect(CloseSuccessor.afterPinned(closing: "F1", isSplit: false, previous: "D", hasPage: { _ in false }) == nil)
+ }
+
+ @Test func theClosingTabIsNeverItsOwnSuccessor() {
+ #expect(next("A", previous: "A", loaded: ["A"]) == "B")
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 4c145c3..dda2c8d 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -51,6 +51,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
startContentBlocking()
SoftwareUpdater.shared.start(app: self)
buildMenus()
+ store.hasPage = { [unowned self] in self.runtime(for: $0) != nil }
NotificationCenter.default.addObserver(forName: .craKeyBindingsChanged, object: nil, queue: .main) { [weak self] _ in
Task { @MainActor in self?.buildMenus() }
}
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index b22725d..1fe5fc0 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -39,6 +39,11 @@ final class SidebarStore {
@ObservationIgnored private(set) var lastNormalWindowID = UUID()
/// Spaces of incognito windows. Not in `spaceOrder`, never saved.
private(set) var incognitoSpaceIDs: Set<UUID> = []
+ /// Per window, the tab shown before the selected one: a close goes back to it (CloseSuccessor).
+ /// Not saved: after a relaunch it has no page, so Arc wouldn't go back to it either.
+ @ObservationIgnored private var previousTab: [UUID: UUID] = [:]
+ /// Whether a tab's page is loaded; AppDelegate asks the windows' browser managers.
+ @ObservationIgnored var hasPage: (UUID) -> Bool = { _ in true }
// MARK: Persistence
@@ -206,7 +211,12 @@ final class SidebarStore {
guard let i = prefs.windows.firstIndex(where: { $0.id == (id ?? activeWindowID) }) else { return }
var w = prefs.windows[i]
change(&w)
- if w != prefs.windows[i] { prefs.windows[i] = w }
+ guard w != prefs.windows[i] else { return }
+ // Whatever changes what the window shows (a pick, a close, a space switch), the tab it
+ // showed is the one a close goes back to (CloseSuccessor; Arc counts space switches too).
+ let shown = { (s: WindowSession) in s.focusedSpaceID.flatMap { s.selectedTabPerSpace[$0] } }
+ if shown(w) != shown(prefs.windows[i]) { previousTab[w.id] = shown(prefs.windows[i]) }
+ prefs.windows[i] = w
}
/// A new window on `spaceID` with nothing open yet.
@@ -415,10 +425,24 @@ final class SidebarStore {
$0.focusedSpaceID = sid
$0.selectedTabPerSpace[sid] = id
}
- var updated = it
- updated.isUnread = false
- if var t = updated.tab { t.timeLastActiveAt = clock.now; updated.data = .tab(t) }
- items[id] = updated
+ noteShown(id)
+ if !isIncognito(space: sid) {
+ var dates = ranking.recentlySwitchedToTabs[id] ?? []
+ dates.append(clock.now)
+ if dates.count > 10 { dates.removeFirst(dates.count - 10) }
+ ranking.recentlySwitchedToTabs[id] = dates
+ rankingFile.save(ranking)
+ }
+ touch()
+ }
+
+ /// A tab coming on screen, picked or handed the selection by a close: it's read and last
+ /// active now (Arc clears the unread mark either way).
+ private func noteShown(_ id: UUID) {
+ guard var it = items[id] else { return }
+ it.isUnread = false
+ if var t = it.tab { t.timeLastActiveAt = clock.now; it.data = .tab(t) }
+ items[id] = it
// Selecting a pane focuses it inside its split (Arc: focusItemID).
if let p = it.parentID, var split = items[p], var s = split.split {
s.focusTabID = id
@@ -430,14 +454,6 @@ final class SidebarStore {
let peeks = FolderPeek.opening(id, folders: folderChain(of: id), isExpanded: { self._prefs.expandedFolders.contains($0) },
peeks: _prefs.peekedFolders)
if peeks != _prefs.peekedFolders { prefs.peekedFolders = peeks }
- if !isIncognito(space: sid) {
- var dates = ranking.recentlySwitchedToTabs[id] ?? []
- dates.append(clock.now)
- if dates.count > 10 { dates.removeFirst(dates.count - 10) }
- ranking.recentlySwitchedToTabs[id] = dates
- rankingFile.save(ranking)
- }
- touch()
}
func updateTab(_ id: UUID, url: String? = nil, title: String? = nil) {
@@ -946,21 +962,27 @@ final class SidebarStore {
moveItem(id, to: space.pinnedContainerID, index: nil)
}
- func moveTab(_ id: UUID, toSpace sid: UUID) {
+ /// `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)
}
- // A window that had it open in the old space picks the next tab there, as on close.
+ // 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 }
for w in prefs.windows {
guard let sel = w.selectedTabPerSpace[from], moved.contains(sel) else { continue }
- updateWindow(w.id) { $0.selectedTabPerSpace[from] = nextSelection(after: it, in: from) }
+ let next = w.id == following ? nil
+ : closeSuccessor(of: sel, in: from, window: w.id, list: list.filter { $0 == sel || !moved.contains($0) })
+ updateWindow(w.id) { $0.selectedTabPerSpace[from] = next }
+ if let next, w.focusedSpaceID == from { noteShown(next) }
}
}
@@ -970,7 +992,7 @@ final class SidebarStore {
func moveTabAndFollow(_ id: UUID, toSpace sid: UUID, window: UUID? = nil) -> Bool {
let moving = splitContaining(id)?.id ?? id
guard items[id]?.isTab == true, spaces[sid] != nil, spaceID(ofItem: moving) != sid else { return false }
- moveTab(moving, toSpace: sid)
+ moveTab(moving, toSpace: sid, following: self.window(window).id)
guard spaceID(ofItem: moving) == sid else { return false }
selectTab(id, window: window)
return true
@@ -1072,6 +1094,18 @@ final class SidebarStore {
return inside.filter { listed.contains($0.id) }
}
+ /// The tabs a container shows as rows, top to bottom: an open folder's, a closed folder's
+ /// peeked ones, one pane per split (its focused one). Arc hands a close over to the row
+ /// above or below among these, never to a tab hidden in a closed folder (#105).
+ func shownTabs(under id: UUID) -> [UUID] {
+ children(of: id).flatMap { c -> [UUID] in
+ if c.isTab { return [c.id] }
+ if let s = c.split { return [s.focusTabID.flatMap { c.children.contains($0) ? $0 : nil } ?? c.children.first].compactMap { $0 } }
+ guard c.isFolder else { return [] }
+ return _prefs.expandedFolders.contains(c.id) ? shownTabs(under: c.id) : peekedTabs(in: c.id).map(\.id)
+ }
+ }
+
/// The folders an item sits in, outermost first.
private func folderChain(of id: UUID) -> [UUID] {
var out: [UUID] = []
@@ -1295,6 +1329,7 @@ final class SidebarStore {
let split = splitContaining(id)
let folder = it.parentID.flatMap { items[$0]?.isFolder == true ? $0 : nil }
let index = folder.flatMap { items[$0]?.children.firstIndex(of: id) }
+ let list = pinned ? [] : (sid.flatMap { spaces[$0] }.map { shownTabs(under: $0.todayContainerID) } ?? [])
// Closed out of a live folder: the item stays out (Arc: hiddenItems). The archive keeps
// the live copy so ⇧⌘T can put it back.
if let folder, items[folder]?.isLiveFolder == true {
@@ -1309,31 +1344,35 @@ final class SidebarStore {
if archive.count > 2000 { archive.removeLast(archive.count - 2000) }
}
if !selectedIn.isEmpty, let sid {
- // Closing a pane keeps the split on screen: focus a neighbour pane.
- let next = split.flatMap { s in items[s.id]?.children.first { items[$0]?.isTab == true } } ?? nextSelection(after: it, in: sid)
- for w in selectedIn { updateWindow(w) { $0.selectedTabPerSpace[sid] = next } }
+ for w in selectedIn {
+ // Closing a pane keeps the split on screen: focus a neighbour pane. The split
+ // still goes back to the tab shown before it (Arc).
+ let kept = previousTab[w]
+ let next = split.flatMap { s in items[s.id]?.children.first { items[$0]?.isTab == true } }
+ ?? closeSuccessor(of: id, in: sid, window: w, list: list)
+ updateWindow(w) { $0.selectedTabPerSpace[sid] = next }
+ guard focusedSpaceID(window: w) == sid else { continue }
+ if split != nil { previousTab[w] = kept }
+ if let next { noteShown(next) }
+ }
}
if let split { collapseSplitIfNeeded(split.id) }
touch()
}
- /// Arc goes back to the tab you came from (activeTabBeforeCreationID) and
- /// otherwise to the neighbour in the list.
- private func nextSelection(after closed: SidebarItem, in sid: UUID) -> UUID? {
- if let back = closed.tab?.activeTabBeforeCreationID, items[back]?.isTab == true, spaceID(ofItem: back) == sid {
- return back
- }
- let list = visibleTabs(in: sid)
- guard !list.isEmpty else { return nil }
- if let p = closed.parentID, let siblings = items[p]?.children {
- // Prefer the sibling that took the closed tab's slot (the one below it).
- let today = tabs(under: p)
- if let first = today.first { _ = first }
- _ = siblings
- }
- // Fall back to the top-most today tab, then the first visible tab.
- if let space = spaces[sid], let first = tabs(under: space.todayContainerID).first { return first.id }
- return list.first?.id
+ /// The tab shown once the selected `id` closes in window `w`: `list` is the space's Today
+ /// tabs while `id` is still among them, empty for a pinned tab.
+ private func closeSuccessor(of id: UUID, in sid: UUID, window w: UUID, list: [UUID]) -> UUID? {
+ let back = previousTab[w].flatMap { spaceID(ofItem: $0) == sid ? $0 : nil }
+ return CloseSuccessor.next(closing: id, previous: back, hasPage: hasPage, list: list)
+ }
+
+ /// A pinned tab, favorite or pinned split closed (unloaded) while selected: the tab to show
+ /// instead, if any.
+ func closeSuccessor(ofPinned id: UUID, window w: UUID) -> UUID? {
+ guard let sid = spaceID(ofItem: id) else { return nil }
+ let back = previousTab[w].flatMap { spaceID(ofItem: $0) == sid ? $0 : nil }
+ return CloseSuccessor.afterPinned(closing: id, isSplit: splitContaining(id) != nil, previous: back, hasPage: hasPage)
}
@discardableResult
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 495b27e..8da20d7 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -1326,20 +1326,17 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
_ = store.resetPinnedTab(p)
for w in app.mainWindows { w.browsers.unload(p) }
}
- if wasSelected {
- // Arc goes back to the tab used before this one, if it is still open. A pinned
- // tab that was closed (unloaded) doesn't count: two of them would otherwise hand
- // the selection back and forth on every ⌘W, reloading each other.
- let back = openRecentTabs(limit: .max).first { !panes.contains($0) }
- store.selectTab(back, window: windowID)
- }
+ // Arc goes back to the tab shown before this one if its page is still loaded, and
+ // otherwise shows nothing (CloseSuccessor). The panes were just unloaded, so they
+ // don't count.
+ if wasSelected { store.selectTab(store.closeSuccessor(ofPinned: id, window: windowID), window: windowID) }
} else {
store.archiveTab(id, reason: .manual)
}
}
/// The space's open tabs, the latest first. A pinned tab that was closed (unloaded) isn't
- /// open: ⌃Tab doesn't list it and ⌘W doesn't go back to it.
+ /// open: ⌃Tab doesn't list it.
private func openRecentTabs(limit: Int) -> [UUID] {
Array(store.recentTabs(in: focusedSpaceID, limit: .max)
.filter { $0 == selectedTabID || !store.isPinned($0) || app.runtime(for: $0) != nil }
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index ea86f8f..6d4b5ad 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -29,6 +29,7 @@ enum StoreTests {
pinnedURL()
moveTabToSpace()
folderPeek()
+ closeSuccessor()
print("Store: \(checks) checks passed")
}
@@ -351,7 +352,7 @@ enum StoreTests {
expect(store.moveTabAndFollow(tab.id, toSpace: work), "a tab moves to another space")
expect(store.focusedSpaceID == work && store.selectedTabID == tab.id, "the window follows it there with the tab selected")
expect(store.children(of: store.space(work)!.todayContainerID).first?.id == tab.id, "it lands at the top of Today")
- expect(store.selectedTabID(in: home) == stay.id, "the space it left goes back to the tab it came from")
+ expect(store.selectedTabID(in: home) == nil, "the window that went along leaves nothing selected in the space it left (Arc)")
expect(store.focusedSpaceID(window: other.id) == home && store.selectedTabID(in: home, window: other.id) == stay.id,
"another window that had it open stays in its space and opens the next tab")
expect(!store.moveTabAndFollow(tab.id, toSpace: work) && store.focusedSpaceID == work, "moving to its own space does nothing")
@@ -395,6 +396,151 @@ enum StoreTests {
expect(store.integrityProblems().isEmpty, "the sidebar stays sound")
}
+ /// The tab shown after ⌘W (Arc 1.171, GitHub #105): the one shown before while its page is
+ /// loaded, else the Today neighbour above (below at the top), else nothing; it reads as read.
+ @MainActor
+ private static func closeSuccessor() {
+ let store = AppComposition(clock: ManualScheduler()).store
+ var loaded: Set<UUID> = []
+ store.hasPage = { loaded.contains($0) }
+ // Earlier tests left tabs in the data folder.
+ for tab in store.tabs(under: store.focusedSpace.todayContainerID) { store.archiveTab(tab.id, reason: .manual) }
+ let source = store.createTab(url: "https://example.com/list", pinned: true)
+ // Opened in the background from the pinned list: Today is c, b, a.
+ let a = store.createTab(url: "https://example.com/a", select: false)
+ let b = store.createTab(url: "https://example.com/b", select: false)
+ let c = store.createTab(url: "https://example.com/c", select: false)
+ loaded = [source.id, a.id, b.id, c.id]
+ store.selectTab(a.id)
+ store.archiveTab(a.id, reason: .manual)
+ expect(store.selectedTabID == source.id, "closing a post picked from the list goes back to the list")
+
+ store.selectTab(c.id)
+ store.selectTab(b.id)
+ store.archiveTab(b.id, reason: .manual)
+ expect(store.selectedTabID == c.id, "back to the tab shown before, not to the tab it was opened from")
+
+ loaded.remove(source.id)
+ let d = store.createTab(url: "https://example.com/d", select: false)
+ store.selectTab(source.id)
+ store.selectTab(c.id)
+ expect(store.item(d.id)?.isUnread == true, "a tab opened in the background is unread")
+ store.archiveTab(c.id, reason: .manual)
+ expect(store.selectedTabID == d.id, "a closed pinned tab isn't reloaded: the neighbour above instead")
+ expect(store.item(d.id)?.isUnread == false, "the tab a close hands over to is read")
+
+ let e = store.createTab(url: "https://example.com/e", select: false)
+ store.archiveTab(d.id, reason: .manual)
+ expect(store.selectedTabID == e.id, "the tab shown before has closed: the neighbour above")
+ store.archiveTab(e.id, reason: .manual)
+ expect(store.selectedTabID == nil, "the last tab hands over to nothing, not to a pinned tab")
+
+ let p2 = store.createTab(url: "https://example.com/p2", pinned: true)
+ loaded = [source.id, p2.id]
+ store.selectTab(source.id)
+ store.selectTab(p2.id)
+ expect(store.closeSuccessor(ofPinned: p2.id, window: store.activeWindowID) == source.id,
+ "a closed pinned tab goes back to the tab shown before")
+ loaded.remove(p2.id)
+ store.selectTab(source.id)
+ loaded.remove(source.id)
+ expect(store.closeSuccessor(ofPinned: source.id, window: store.activeWindowID) == nil,
+ "and to nothing when that one was closed too")
+
+ // A Today folder above: its tabs are the neighbour only while it's open (Arc).
+ let today = store.focusedSpace.todayContainerID
+ let folder = store.createFolder(named: "Folder", in: today, index: 0)
+ let x = store.createTab(url: "https://example.com/x", select: false, parent: folder.id)
+ let y = store.createTab(url: "https://example.com/y", select: false, parent: folder.id, index: 1)
+ let f = store.createTab(url: "https://example.com/f", select: false, index: 1)
+ loaded = []
+ store.setExpanded(folder.id, false)
+ store.selectTab(f.id)
+ expect(store.shownTabs(under: today) == [f.id], "a closed folder shows none of its tabs")
+ store.archiveTab(f.id, reason: .manual)
+ expect(store.selectedTabID == nil, "so a close doesn't open a tab hidden in it")
+ let g = store.createTab(url: "https://example.com/g", select: false, index: 1)
+ store.setExpanded(folder.id, true)
+ store.selectTab(g.id)
+ expect(store.shownTabs(under: today) == [x.id, y.id, g.id], "an open folder shows its tabs")
+ store.archiveTab(g.id, reason: .manual)
+ expect(store.selectedTabID == y.id, "and the row above it, inside the folder, takes over")
+
+ // Two windows on one space: each goes back to the tab it showed before.
+ store.setExpanded(folder.id, false)
+ let main = store.activeWindowID
+ let second = store.addWindow(spaceID: store.focusedSpaceID, frame: nil).id
+ let h = store.createTab(url: "https://example.com/h", select: false)
+ let i = store.createTab(url: "https://example.com/i", select: false)
+ let j = store.createTab(url: "https://example.com/j", select: false)
+ let k = store.createTab(url: "https://example.com/k", select: false)
+ loaded = [h.id, i.id, j.id, k.id]
+ store.selectTab(h.id, window: main)
+ store.selectTab(i.id, window: main)
+ store.selectTab(j.id, window: second)
+ store.selectTab(k.id, window: second)
+ store.archiveTab(k.id, reason: .manual)
+ expect(store.selectedTabID(in: store.focusedSpaceID, window: second) == j.id
+ && store.selectedTabID(in: store.focusedSpaceID, window: main) == i.id, "the second window goes back to its own previous tab")
+ store.archiveTab(i.id, reason: .manual)
+ expect(store.selectedTabID(in: store.focusedSpaceID, window: main) == h.id, "and the first to its own")
+
+ // Moving the open tab to another space without following it: the space it left
+ // hands over as on a close, and the tab shown there is read.
+ let work = store.createSpace(title: "Work", emoji: "💼", focus: false).id
+ let m = store.createTab(url: "https://example.com/m", select: false, window: main)
+ let n = store.createTab(url: "https://example.com/n", select: false, window: main)
+ loaded.insert(m.id)
+ store.selectTab(m.id, window: main)
+ store.selectTab(n.id, window: main)
+ store.markUnread(m.id)
+ store.moveTab(n.id, toSpace: work)
+ expect(store.selectedTabID(in: store.focusedSpaceID(window: main), window: main) == m.id, "moving it away goes back to the tab shown before")
+ expect(store.item(m.id)?.isUnread == false, "which is read")
+
+ // A space switch counts as showing another tab (Arc): after going away and back, the
+ // tab shown before is in the other space, so a close takes the neighbour instead.
+ let space1 = store.focusedSpaceID(window: main)
+ let w1 = store.createTab(url: "https://example.com/w1", select: false, window: main)
+ let x1 = store.createTab(url: "https://example.com/x1", select: false, window: main)
+ let y1 = store.createTab(url: "https://example.com/y1", select: false, window: main)
+ let other = store.createTab(url: "https://example.com/other", in: work, select: false)
+ loaded = [w1.id, x1.id, y1.id, other.id]
+ store.selectTab(other.id, window: main)
+ store.selectTab(w1.id, window: main)
+ store.selectTab(x1.id, window: main)
+ store.focusSpace(work, window: main)
+ store.focusSpace(space1, window: main)
+ expect(store.shownTabs(under: store.space(space1)!.todayContainerID).prefix(3) == [y1.id, x1.id, w1.id], "new tabs go to the top of Today")
+ store.archiveTab(x1.id, reason: .manual)
+ expect(store.selectedTabID(in: space1, window: main) == y1.id,
+ "a round trip through another space: the neighbour above, not the tab picked before")
+
+ // Closing a pane keeps the tab shown before the split.
+ let before = store.createTab(url: "https://example.com/before", select: false, window: main)
+ let l = store.createTab(url: "https://example.com/l", select: false, window: main)
+ let r = store.createTab(url: "https://example.com/r", select: false, window: main)
+ _ = store.createSplit(with: [l.id, r.id])
+ loaded = [before.id, l.id, r.id]
+ store.selectTab(before.id, window: main)
+ store.selectTab(l.id, window: main)
+ store.archiveTab(l.id, reason: .manual)
+ expect(store.selectedTabID(in: space1, window: main) == r.id, "the other pane stays")
+ store.archiveTab(r.id, reason: .manual)
+ expect(store.selectedTabID(in: space1, window: main) == before.id, "then the split goes back to the tab shown before it")
+
+ // A pinned split closing hands over to nothing, even with the tab shown before loaded.
+ let pl = store.createTab(url: "https://example.com/pl", select: false, window: main)
+ let pr = store.createTab(url: "https://example.com/pr", select: false, window: main)
+ _ = store.createSplit(with: [pl.id, pr.id])
+ store.togglePinned(pl.id)
+ expect(store.isPinned(pl.id) && store.splitContaining(pl.id) != nil, "a pinned split")
+ loaded = [before.id, pl.id, pr.id]
+ store.selectTab(before.id, window: main)
+ store.selectTab(pl.id, window: main)
+ expect(store.closeSuccessor(ofPinned: pl.id, window: main) == nil, "a pinned split hands over to nothing (Arc)")
+ }
+
/// A closed folder keeps its open tab in sight (Arc, GitHub #85): picking a tab two closed
/// folders down lists it under the outer one without opening either.
@MainActor
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 108f01d..0950e6f 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2185,12 +2185,13 @@ Two new Arc windows, both with View ▸ Hide Sidebar and a tab selected, capture
(scratch, 40 fps), not kept.
- Reported by Anoninz on #86, not captured here: the sidebar's right-click Move to ▸ <space> on the open tab
follows too (the row leaves, Arc switches to that space and selects the tab).
-- [U] What the space the tab left selects afterwards, and what Move to ▸ does on a tab that isn't open: other
- sessions were driving Arc at the time and a posted ⌃2 never reached the window.
+- [O] What the space the tab left selects afterwards: nothing (measured for #105, see "The tab shown after ⌘W").
+- [U] What Move to ▸ does on a tab that isn't open: other sessions were driving Arc at the time and a posted ⌃2
+ never reached the window.
- Cra: `SidebarStore.moveTabAndFollow` for the command bar's Move Tab to <space> and the new Move Tab to Space N
(⌃⌘1–9, Cra's own: ⌘ added to Go to Space N; neither Arc nor macOS binds ⌃⌘ + a digit). A pane brings its split.
- The sidebar menu's Move to Space follows when it moves the open tab or its split; another tab moves on its own. Whatever moves, a window that had it open in the
- old space opens the next tab there, picked as on close.
+ The sidebar menu's Move to Space follows when it moves the open tab or its split; another tab moves on its own. The window that follows leaves nothing selected in
+ the old space; another window that had it open there opens the next tab, picked as on close.
## Sending a Little Arc's page to a space (Arc 1.171, 2 Nov 2026, issue #92)
@@ -2347,3 +2348,37 @@ tap with a real Shift key held around them; the space read from each window's `s
`ForceWebRequestProxyForTest` makes `MayHaveProxies()` always true, so a proxy extension enabled later does not
reset the URL loader factories. Cra logs the winner and the overridden ones per profile when they change, and
Export Diagnostics' summary.txt has a "Proxy:" section.
+
+## The tab shown after ⌘W (Arc 1.171, 2 Nov 2026, issue #105, offline Arc driven through its menus)
+Offline Arc as in "One space": one space with pinned S and P2 and Today C, B, A, D (A, B, C saved with
+`activeTabBeforeCreationID` and `referrerID` = S, unread), the selected tab and the window's
+`itemLastActiveDates` set in StorableWindows.json, then Tabs ▸ Next/Previous Tab and File ▸ Archive Tab (Close
+Tab on a pinned tab) pressed over AX, a window capture after each step. Setting AXSelected on a row
+doesn't pick a tab, and the selection saved in StorableWindows.json wasn't always honoured; navigate instead.
+- [O] Arc goes back to the tab shown just before the closed one, if its page is still loaded: D → A, close A → D
+ (not S, the tab A was opened from, loaded or not); S → P2 → close P2 hands back to S only while S is loaded.
+- [O] Only that one tab counts. D → A → B, close B → A, close A → C (the neighbour above), not D: Arc doesn't
+ walk further back. A previous tab without a page doesn't count either: one restored from `itemLastActiveDates`
+ that hasn't loaded since launch, or a pinned tab closed with ⌘W (Arc never reloads it on a later close).
+- [O] Otherwise a Today tab hands over to its neighbour, the one above first (B → C, D → A), the one below at
+ the top (C → A), loaded or not. The last Today tab hands over to nothing, with pinned tabs still in the
+ sidebar. A pinned tab hands over to nothing (no neighbour), even with Today pages loaded.
+- [O] "Neighbour" means the Today rows on screen: with a closed folder above it (tabs X, Y inside), closing D hands
+ over to nothing; with the folder open (`AXDisclosing` on its row over AX), to Y, the row above inside it.
+- [O] A favorite closes like a pinned tab: back to the previous tab while it is loaded (F1 after D → D), else nothing.
+ Tabs ▸ Next Tab runs through the favorites first.
+- [O] The tab a close hands over to loses its unread mark, as when it is picked.
+- [O] Splits (a `splitView` item needs `layoutOrientation`, `focusItemID` and `itemWidthFactors`, as Arc saves it;
+ without them Arc moves the split into a pinned "Recently recovered" folder): a split row as the neighbour opens the
+ split on its focused pane. Closing a pane keeps the other one and the tab shown before the split (D → split, close
+ L → R, close R → D, not the neighbour C). Closing a pinned split hands over to nothing even with the tab shown
+ before still loaded (D → pinned split, Close Tab → nothing; twice).
+- [O] Previous tabs are per window: window 1 A → B, window 2 D → C, close C in window 2 → D (not B).
+- [O] A space switch counts as showing another tab: space 1 B, space 2 Y → X, Previous Space (B), Next Space (X),
+ close X → W (the neighbour above), not Y. Closing never switches spaces.
+- [O] Command bar "Move to Today in <space>" on the open tab: the window follows, and the space it left has nothing
+ selected when you come back (C → B, move B, Previous Space → nothing; not C, not the neighbour A).
+- [?] Not measured: Move to ▸ on a tab open in another window.
+- Cra: CloseSuccessor (CraCore) with SidebarStore's per-window `previousTab` (not saved; set in `updateWindow`
+ whenever what the window shows changes) and `hasPage` (a window's browser manager has the page). A tab put to sleep has no page, like Arc's unloaded tabs.
+ `activeTabBeforeCreationID` is still saved and imported but no longer picks the next tab.