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.

A new-tab link clicked inside a Peek opens a tab in the space, as in Arc (#202)

Victora55078d442a2
diff --git a/Packages/CraCore/Sources/CraCore/PeekTrigger.swift b/Packages/CraCore/Sources/CraCore/PeekTrigger.swift
index e912c9d..6f1b624 100644
--- a/Packages/CraCore/Sources/CraCore/PeekTrigger.swift
+++ b/Packages/CraCore/Sources/CraCore/PeekTrigger.swift
@@ -18,4 +18,14 @@ public enum PeekTrigger {
return settings.peekLinksToOtherSites && (settings.peekInEveryTab || fromPinned)
&& (newTab || PinnedNavigation.linkLeavesHost(url, from: page))
}
+
+ /// A link clicked inside the Peek that asks for a new tab (target=_blank, window.open without
+ /// features) leaves the Peek: Arc 1.171 (6 Nov 2026, GitHub #202) closed the Peek and opened
+ /// the page as a selected Today tab in the space, below the tab the Peek came from, with no
+ /// second Little Arc. A Shift-click still loads in the Peek. Only pages a tab can show: an
+ /// about:blank a script fills in later needs its opener, so it stays a popup.
+ public static func leavesPeek(_ url: String, shiftClick: Bool, newTab: Bool) -> Bool {
+ guard newTab, !shiftClick, let scheme = URL(string: url)?.scheme?.lowercased() else { return false }
+ return ["http", "https", "file"].contains(scheme)
+ }
}
diff --git a/Packages/CraCore/Tests/CraCoreTests/PeekTriggerTests.swift b/Packages/CraCore/Tests/CraCoreTests/PeekTriggerTests.swift
index 3a87b51..ffb740c 100644
--- a/Packages/CraCore/Tests/CraCoreTests/PeekTriggerTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/PeekTriggerTests.swift
@@ -41,4 +41,20 @@ struct PeekTriggerTests {
#expect(!Self.opens("file:///tmp/a.html", newTab: true))
#expect(!Self.opens("cra://settings", shift: true))
}
+
+ /// Inside the Peek (GitHub #202).
+ @Test func aNewTabLinkInsideThePeekLeavesIt() {
+ #expect(PeekTrigger.leavesPeek(Self.other, shiftClick: false, newTab: true))
+ #expect(PeekTrigger.leavesPeek(Self.same, shiftClick: false, newTab: true))
+ #expect(PeekTrigger.leavesPeek("HTTPS://example.org/", shiftClick: false, newTab: true))
+ #expect(PeekTrigger.leavesPeek("file:///tmp/a.html", shiftClick: false, newTab: true))
+ // A plain link loads in the Peek, and so does a Shift-click.
+ #expect(!PeekTrigger.leavesPeek(Self.other, shiftClick: false, newTab: false))
+ #expect(!PeekTrigger.leavesPeek(Self.other, shiftClick: true, newTab: false))
+ // Pages a tab can't take without the opener, or that a page must not open.
+ #expect(!PeekTrigger.leavesPeek("about:blank", shiftClick: false, newTab: true))
+ #expect(!PeekTrigger.leavesPeek("", shiftClick: false, newTab: true))
+ #expect(!PeekTrigger.leavesPeek("cra://settings", shiftClick: false, newTab: true))
+ #expect(!PeekTrigger.leavesPeek("javascript:alert(1)", shiftClick: false, newTab: true))
+ }
}
diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swift
index 637015f..f9fad60 100644
--- a/Sources/Cra/Services/BrowserManager.swift
+++ b/Sources/Cra/Services/BrowserManager.swift
@@ -1126,17 +1126,23 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {
}
func browser(_ browser: CraBrowser, requestsNewTabWithURL url: String, inBackground background: Bool) {
+ openLinkTab(url, from: tabID(of: browser), inBackground: background)
+ }
+
+ /// A link that asks for a new tab, from `source`'s page or from a Peek over it (#202): a
+ /// Today tab in `source`'s space, else the window's.
+ func openLinkTab(_ url: String, from source: UUID?, inBackground background: Bool) {
// cra:// is Cra's scripting scheme (DevTools Protocol, key presses); a page must not drive it.
if url.lowercased().hasPrefix("cra:") { return }
- let sourceSpace = tabID(of: browser).flatMap { store.spaceID(ofItem: $0) }
- let parentIndex = tabID(of: browser).flatMap { id -> Int? in
+ let sourceSpace = source.flatMap { store.spaceID(ofItem: $0) }
+ let parentIndex = source.flatMap { id -> Int? in
guard let it = store.item(id), let p = it.parentID, store.rootContainer(of: id) != nil,
case .today = store.rootContainer(of: id)! else { return nil }
return (store.item(p)?.children.firstIndex(of: id) ?? -1) + 1
}
// Links from a today tab open right below it (Arc); otherwise at the top.
let tab = store.createTab(url: url, in: sourceSpace, select: !background,
- parent: parentIndex != nil ? store.item(tabID(of: browser)!)?.parentID : nil,
+ parent: parentIndex != nil ? source.flatMap { store.item($0)?.parentID } : nil,
index: parentIndex, window: windowID)
if background {
store.markUnread(tab.id, true)
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index ad6ea27..8305fec 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -137,6 +137,8 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
/// covers; a click on it, Escape or the close button ends the Peek.
let isPeek: Bool
private(set) weak var peekParent: MainWindowController?
+ /// The tab the Peek came from: links that leave the Peek open as tabs placed from it.
+ private let peekSourceTab: UUID?
private var dim: PeekDimPanel?
private var controls: PeekControlsPanel?
/// The Peek is on its way out (closePeekAnimated).
@@ -173,6 +175,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
isPopupHost = url == nil
isPeek = parent != nil
peekParent = parent
+ peekSourceTab = parent == nil ? nil : fromTab
requestedSpaceID = parent == nil ? space : nil
// Little Windows are normal browsing: they target the last normal window's space
// (a Peek: the space of the window it covers; a cra://open: the space it names).
@@ -1095,22 +1098,46 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
/// A Shift-clicked link opens in this window: Arc's Little Arc has no Peek of its own, so its
/// Shift-click is a plain click (1.171, 3 Nov 2026).
+ /// In a Peek, a target=_blank link leaves it for a tab (PeekTrigger.leavesPeek, #202).
func browser(_ browser: CraBrowser, opensPeekForURL url: String, shiftClick: Bool, newTab: Bool) -> Bool {
- guard shiftClick, !url.lowercased().hasPrefix("cra:") else { return false }
+ if url.lowercased().hasPrefix("cra:") { return false }
+ if isPeek, PeekTrigger.leavesPeek(url, shiftClick: shiftClick, newTab: newTab) {
+ openTabFromPeek(url, inBackground: false)
+ return true
+ }
+ guard shiftClick else { return false }
browser.loadURL(url)
return true
}
- /// Links that want a new tab open another little window (Arc does the same).
+ /// Links that want a new tab open another little window (Arc does the same); a Peek's open
+ /// as tabs in its window's space.
func browser(_ browser: CraBrowser, requestsNewTabWithURL url: String, inBackground background: Bool) {
// cra:// is Cra's scripting scheme; a page must not drive it.
if url.lowercased().hasPrefix("cra:") { return }
+ if isPeek { openTabFromPeek(url, inBackground: background); return }
app.openLittleWindow(url: url, activate: !background, opener: browser)
if background { window?.makeKeyAndOrderFront(nil) }
}
+ /// Arc 1.171 (#202): a link from a Peek that asks for a new tab is a Today tab in the space,
+ /// placed as a link from the tab under the Peek would be, and the Peek closes for it. A
+ /// background one (⌘-click) leaves the Peek open, as the click left the page in a tab.
+ private func openTabFromPeek(_ url: String, inBackground background: Bool) {
+ guard let parent = peekParent else { return }
+ parent.browsers.openLinkTab(url, from: peekSourceTab, inBackground: background)
+ // Not from inside Chromium's popup callback: the Peek's page closes a turn later.
+ if !background { DispatchQueue.main.async { [weak self] in self?.closeWindow() } }
+ }
+
+ /// A popup that needs its opener (a sign-in window) stays a Little Window, over a Peek too:
+ /// closing the Peek for a tab would close the page waiting on it.
func browser(_ browser: CraBrowser, popupHostForURL url: String, inBackground background: Bool) -> CraBrowser? {
if url.lowercased().hasPrefix("cra:") { return nil }
+ if isPeek, background {
+ openTabFromPeek(url, inBackground: true)
+ return nil
+ }
let w = app.makeLittleWindow(url: nil, opener: browser)
w.state.url = url
w.show()
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index fd501f5..6fa6470 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2971,6 +2971,14 @@ event with `shiftClickModalEntryPointEnabled` set for the run, AX frames and 60
the peeked page on the right. Cra: MainWindowController.closedPeek, LittleWindowController.promoteToSplit.
- [?] Not measured: the card at other window widths (Cra keeps 80 % of the area), and the Peek with Arc's
toolbar turned off.
+- [O, 6 Nov, GitHub #202] A target=_blank link clicked inside a Peek (HID click, offline Arc, Peek opened by a
+ Shift-click from a Today tab on a 127.0.0.1 lab page) closed the Peek and opened the page as a new Today tab
+ in the same space, selected, right below the tab the Peek came from. No second Little Arc or Peek, and the
+ peeked page was not kept as a tab. Cra (0.1.31) opened another Little Window. Cra: PeekTrigger.leavesPeek,
+ LittleWindowController.openTabFromPeek → BrowserManager.openLinkTab (the placement links from a tab get, so
+ from a pinned tab the top of Today). Not observed in Arc: a ⌘-click inside the Peek (Cra: a background tab,
+ the Peek stays) and window.open with features (Cra: still a Little Window over the Peek, which keeps the
+ opener alive for sign-ins).
### Peek grows out of the link (Arc 1.171, 6 Nov 2026, GitHub #204, offline Arc)
The reporter recorded Arc 1.172.1 growing the card out of the clicked link. 1.172.0/1.172.1 only moved Chromium