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.

Move Tab to Space N (⌃⌘1–9) sends a Little Window's page there, into the window already showing that space (#92) (#119)

Victor Kildahlaaf424732d6c
diff --git a/Packages/CraCore/Sources/CraCore/SpaceWindow.swift b/Packages/CraCore/Sources/CraCore/SpaceWindow.swift
new file mode 100644
index 0000000..fa5884c
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/SpaceWindow.swift
@@ -0,0 +1,18 @@
+import Foundation
+
+/// Which browser window a page sent to a space opens in: a Little Window's "Open in"
+/// pick or ⌃⌘N (GitHub #92).
+///
+/// Arc 1.171 (2 Nov, two windows on Victor and JYSK, the Victor one used last): picking
+/// JYSK in Little Arc's spaces popover opened the page in the JYSK window and brought that
+/// window forward, and the Victor window kept its space. An offline copy with three windows
+/// showed the rest: with no window on the space, the window in use last switches to it; with
+/// two on it, the one in use last wins, else the frontmost; a minimized one is unminimized.
+public enum SpaceWindow {
+ /// `windows`: the normal (not incognito) browser windows, front to back, minimized ones
+ /// included, each with the space it shows. `lastUsed`: the normal window in use last.
+ public static func window(for space: UUID, windows: [(id: UUID, space: UUID)], lastUsed: UUID) -> UUID {
+ if windows.contains(where: { $0.id == lastUsed && $0.space == space }) { return lastUsed }
+ return windows.first { $0.space == space }?.id ?? lastUsed
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/SpaceWindowTests.swift b/Packages/CraCore/Tests/CraCoreTests/SpaceWindowTests.swift
new file mode 100644
index 0000000..86c5d6a
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/SpaceWindowTests.swift
@@ -0,0 +1,27 @@
+import CraCore
+import Foundation
+import Testing
+
+/// Where a Little Window's page goes when it is sent to a space (GitHub #92).
+struct SpaceWindowTests {
+ let a = UUID(), b = UUID(), c = UUID()
+ let victor = UUID(), jysk = UUID(), work = UUID()
+
+ /// Arc: window A shows Victor and was used last, window B shows JYSK; JYSK goes to B.
+ @Test func aWindowShowingTheSpaceTakesThePage() {
+ #expect(SpaceWindow.window(for: jysk, windows: [(a, victor), (b, jysk)], lastUsed: a) == b)
+ #expect(SpaceWindow.window(for: victor, windows: [(a, victor), (b, jysk)], lastUsed: a) == a)
+ }
+
+ @Test func otherwiseTheWindowInUseLastSwitches() {
+ #expect(SpaceWindow.window(for: work, windows: [(b, jysk), (a, victor)], lastUsed: a) == a)
+ // The window in use can be hidden (the last one closed), so not in the list.
+ #expect(SpaceWindow.window(for: work, windows: [], lastUsed: a) == a)
+ }
+
+ /// Of several windows on the space, the one in use last, else the frontmost.
+ @Test func severalWindowsOnTheSpace() {
+ #expect(SpaceWindow.window(for: jysk, windows: [(b, jysk), (c, jysk), (a, victor)], lastUsed: c) == c)
+ #expect(SpaceWindow.window(for: jysk, windows: [(c, jysk), (b, jysk), (a, victor)], lastUsed: a) == c)
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 3aebd7c..8ae4e7f 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -297,6 +297,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
guard let self, var w = note.object as? NSWindow else { return }
while let parent = w.parent { w = parent }
if let c = self.mainWindows.first(where: { $0.window === w }) { self.store.activeWindowID = c.windowID }
+ self.littleWindows.first { $0.window === w }?.refreshTarget()
}
}
}
@@ -325,6 +326,20 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
return main
}
+ /// The normal window a page sent to `spaceID` opens in (SpaceWindow): one already showing
+ /// the space, else the one in use last, which then switches to it.
+ @discardableResult
+ func useNormalWindow(forSpace spaceID: UUID) -> MainWindowController {
+ let last = useNormalWindow()
+ guard !last.isIncognito else { return last }
+ var seen = Set<UUID>()
+ let normal = NSApp.orderedWindows.compactMap { w in mainWindows.first { $0.window === w } }
+ .filter { !$0.isIncognito && seen.insert($0.windowID).inserted }
+ .map { (id: $0.windowID, space: store.focusedSpaceID(window: $0.windowID)) }
+ store.activeWindowID = SpaceWindow.window(for: spaceID, windows: normal, lastUsed: last.windowID)
+ return main
+ }
+
/// Arc's New Window (⌘N): another window on the space in use, cascaded from the
/// current one, with the command bar up. With every window closed it brings the
/// hidden one back instead. New Incognito Window (⇧⌘N) always opens a new one.
@@ -675,7 +690,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
case "addSplitView": return store.selectedTabID != nil
case "editSpace", "deleteSpace", "nextSpace", "previousSpace", "manageSpaces": return !main.isIncognito
case "closeLittleWindows": return !littleWindows.isEmpty
- case let id? where id.hasPrefix("moveTabToSpace"): return store.selectedTabID != nil && !main.isIncognito
+ case let id? where id.hasPrefix("moveTabToSpace"):
+ guard let n = Int(id.dropFirst(14)), n >= 1, n <= store.spaceOrder.count else { return false }
+ if let little = keyLittleWindow { return little.hasPage }
+ return store.selectedTabID != nil && !main.isIncognito
default: break
}
return true
diff --git a/Sources/Cra/UI/Settings/ShortcutsPane.swift b/Sources/Cra/UI/Settings/ShortcutsPane.swift
index 879c555..682d1a7 100644
--- a/Sources/Cra/UI/Settings/ShortcutsPane.swift
+++ b/Sources/Cra/UI/Settings/ShortcutsPane.swift
@@ -240,7 +240,7 @@ enum ShortcutDescriptions {
if let t = table[a.id] { return t }
if a.id.hasPrefix("item"), let n = a.id.dropFirst(4).first { return "Switch to the \(n). tab in the sidebar." }
if a.id.hasPrefix("space"), let n = a.id.dropFirst(5).first { return "Switch to the \(n). space." }
- if a.id.hasPrefix("moveTabToSpace"), let n = a.id.dropFirst(14).first { return "Move the current tab to the \(n). space and switch to it." }
+ if a.id.hasPrefix("moveTabToSpace"), let n = a.id.dropFirst(14).first { return "Move the current tab, or a Little Window's page, to the \(n). space and switch to it." }
return a.name + "."
}
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index bb10614..f2c1fcc 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -22,7 +22,8 @@ final class LittleWindowState {
var isLoading = false
var progress: Double = 0
var themeColor = ""
- /// The space ⌘O opens into (the focused space when the window was made).
+ /// The space ⌘O opens into: the focused space of the window in use last, as of when
+ /// this window last took focus (Arc's Little Arc, see `refreshTarget`).
var targetSpaceID: UUID
var popupOpen = false
/// Pointer hover, tracked by AppKit (SwiftUI's onHover sleeps while the
@@ -438,6 +439,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
app.perform(id)
case .switchSpace(let id):
store.focusSpace(id)
+ refreshTarget()
case .moveToSpace(let id):
promote(to: id)
case .moveToFolder:
@@ -533,24 +535,34 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
// MARK: Promote / close
+ /// Arc's Little Arc names the space of the browser window used last and updates when it
+ /// takes focus again (Arc 1.171: switched in the main window, "Open in" followed; #92).
+ func refreshTarget() {
+ let id = peekParent?.focusedSpaceID ?? store.focusedSpaceID(window: store.lastNormalWindowID)
+ if state.targetSpaceID != id { state.targetSpaceID = id }
+ }
+
/// Move the page into a space (nil = the window's target space) as a Today
- /// tab. The live browser goes with it, so history, scroll position and
- /// logins stay.
+ /// tab, in the window already showing that space if there is one (Arc). The
+ /// live browser goes with it, so history, scroll position and logins stay.
func promote(to spaceID: UUID?) {
guard let b = browser, hasPage else { return }
closePopup()
commandBar.close()
app.useNormalWindow()
- let sid = (spaceID ?? state.targetSpaceID).flatMap { store.space($0) != nil && !store.isIncognito(space: $0) ? $0 : nil }
- ?? store.focusedSpaceID
- let tab = store.createTab(url: b.currentURL, title: b.currentTitle, in: sid, select: true)
+ if spaceID == nil { refreshTarget() }
+ let wanted = spaceID ?? state.targetSpaceID
+ let sid = store.space(wanted) != nil && !store.isIncognito(space: wanted) ? wanted : store.focusedSpaceID
+ // Held: closing this window can make another browser window key, which changes app.main.
+ let target = app.useNormalWindow(forSpace: sid)
+ let tab = store.createTab(url: b.currentURL, title: b.currentTitle, in: sid, select: true, window: target.windowID)
if let favicon, let key = FaviconKey.key(for: b.currentURL) { app.favicons.store(favicon, forKey: key) }
promoted = true
browser = nil
- app.main.browsers.adopt(b, for: tab.id)
+ target.browsers.adopt(b, for: tab.id)
window?.close()
- app.main.showWindow(nil)
- app.main.window?.makeKeyAndOrderFront(nil)
+ target.showWindow(nil)
+ target.window?.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
}
@@ -587,6 +599,9 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
browser?.showDevTools()
case "print": browser?.print()
case "promoteLittleWindow": promote(to: nil)
+ // Move Tab to Space N (⌃⌘N, #86) sends the page there, as the spaces popup does (#92).
+ case let id where id.hasPrefix("moveTabToSpace"):
+ if let n = Int(id.dropFirst(14)), n >= 1, n <= store.spaceOrder.count { promote(to: store.spaceOrder[n - 1]) }
// No find bar or capture in little windows; keep them off the main window.
case "find", "findNext", "findPrevious", "capturePage", "toggleSidebar", "pinTab", "favoriteTab", "renameTab",
"duplicateTab", "resetTab", "muteTab", "clearToday", "nextTab", "previousTab", "recentTab", "recentTabBackward":
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index e5e3e60..b2c2264 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2192,6 +2192,32 @@ Two new Arc windows, both with View ▸ Hide Sidebar and a tab selected, capture
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.
+## Sending a Little Arc's page to a space (Arc 1.171, 2 Nov 2026, issue #92)
+
+Victor's Arc, a second window of my own (File ▸ New Window over AX, switched to JYSK through the Spaces menu while
+Arc was frontmost, closed afterwards), Little Arcs opened with `open -a Arc https://example.com/?cra92…`, the spaces
+popover driven by AX (the chevron is `openInSpaceExpander`, the rows are AXButtons named after the space).
+
+- [O AX] Window A on Victor (used last), window B on JYSK. Picking JYSK in the Little Arc's popover closed the Little
+ Arc and opened the page in **window B**, which came forward and became main; window A kept Victor.
+- [O AX] No shortcut for it: Tabs ▸ "Open Little Arc or Peek in…" is ⌘O (the target space), Spaces lists the spaces
+ under ⌃1…; a ⌃2 posted to Arc's pid while the Little Arc was key changed nothing.
+- Offline copy (cra-88's fake home, no network, spaces Alpha/Beta/Gamma, up to three windows W1–W3, Little Arcs
+ from File ▸ New Little Arc Window; the popover rows are AXButtons `d='<space>'` in their own window, present only
+ while it is open; the real chevron is the second `openInSpaceExpander`, `d=''`):
+ - [O AX] "Open in <space> ⌘O" names the focused space of the window used last, read when the Little Arc takes focus:
+ W1 switched Alpha → Beta while the Little Arc sat behind it, the button still said Alpha until the Little Arc was
+ focused again, then Beta. Using W2 (Gamma) after opening the Little Arc from W1 (Alpha) made it say Gamma.
+ - [O AX] ⌘O and a click on that button open the page there: in W1's new space, and in W2 after W2 was used.
+ - [O AX] No window shows the picked space: the window used last switches to it and takes the page.
+ - [O AX] Two windows show it: the one used last if it is one of them, else the frontmost of them (W1 and W2 on Beta,
+ W3 on Alpha used last: whichever of W1/W2 was raised later took the page, both ways round).
+ - [O AX] Only a minimized window shows it: Arc unminimizes that window and opens the page there.
+- Cra: `SpaceWindow` (CraCore) picks the window: the one in use if it shows the space, else the frontmost one that
+ does, else the one in use, which switches. It applies to ⌘O, the popover, the command bar's Move to <space> and
+ Move Tab to Space N (⌃⌘1–9, #86), which in a Little Window sends its page (#92, Cra's own like ⌃⌘N itself). The
+ Little Window's target follows the window used last when it takes focus (`refreshTarget`), as Arc's does.
+
## ⌘Return in the command bar and closed folders that keep their tab (Arc 1.171, 2 Nov 2026, issue #85)
Victor's Arc, a window of my own (File ▸ New Window over AX, closed afterwards), keys posted to Arc's pid while it