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.

The sidebar follows the active row, as in Arc (#47) (#64)

Victor Kildahl4d1c324bc0dc
diff --git a/Sources/Cra/Model/SidebarModel.swift b/Sources/Cra/Model/SidebarModel.swift
index 6ff1be5..401a041 100644
--- a/Sources/Cra/Model/SidebarModel.swift
+++ b/Sources/Cra/Model/SidebarModel.swift
@@ -338,8 +338,11 @@ struct AppSettings: Codable, Equatable {
var searchEngine: SearchEngine = .google
var newTabsAtTop: Bool = true
/// Tabs ▸ "Show the New Tab button above tabs": the + New Tab row leads Today
- /// instead of following its last tab.
- var newTabButtonAtTop: Bool = false
+ /// instead of following its last tab. On like Arc, which keeps it under the divider.
+ var newTabButtonAtTop: Bool = true
+ /// Cra 0.1.15–0.1.23 saved the New Tab row below Today for everyone; settings without
+ /// this mark move it back above, where Arc has it, once.
+ var newTabButtonDefaultMigrated: Bool = true
var showStatusBar: Bool = true
/// Arc's toolbar above the page (URL, copy link, DevTools). ⇧⌘D toggles. Off by
/// default like Arc, which keeps the URL at the top of the sidebar.
@@ -475,7 +478,9 @@ extension AppSettings {
autoArchive = try c.decodeIfPresent(AutoArchiveThreshold.self, forKey: .autoArchive) ?? .twelveHours
searchEngine = try c.decodeIfPresent(SearchEngine.self, forKey: .searchEngine) ?? .google
newTabsAtTop = try c.decodeIfPresent(Bool.self, forKey: .newTabsAtTop) ?? true
- newTabButtonAtTop = try c.decodeIfPresent(Bool.self, forKey: .newTabButtonAtTop) ?? false
+ if try c.decodeIfPresent(Bool.self, forKey: .newTabButtonDefaultMigrated) == true {
+ newTabButtonAtTop = try c.decodeIfPresent(Bool.self, forKey: .newTabButtonAtTop) ?? true
+ }
showStatusBar = try c.decodeIfPresent(Bool.self, forKey: .showStatusBar) ?? true
if try c.decodeIfPresent(Bool.self, forKey: .toolbarDefaultMigrated) == true {
showToolbar = try c.decodeIfPresent(Bool.self, forKey: .showToolbar) ?? false
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
index b548b1d..a35e5ff 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
@@ -546,9 +546,24 @@ class SidebarRowView: NSView {
fillLayer.backgroundColor = fill.cgColor
}
+ /// The open row's soft shadow under its fill, on light themes only.
+ func setLifted(_ selected: Bool) {
+ let lifted = selected && !colors.isDark && decor.combine == nil
+ layer?.shadowOpacity = lifted ? 0.06 : 0
+ if lifted {
+ layer?.shadowColor = NSColor.black.cgColor
+ layer?.shadowRadius = 3
+ layer?.shadowOffset = CGSize(width: 0, height: -1)
+ layer?.shadowPath = CGPath(roundedRect: fillRect, cornerWidth: CraMetrics.rowCorner, cornerHeight: CraMetrics.rowCorner, transform: nil)
+ }
+ }
+
override func layout() {
super.layout()
fillLayer.frame = fillRect
+ if layer?.shadowOpacity ?? 0 > 0 {
+ layer?.shadowPath = CGPath(roundedRect: fillRect, cornerWidth: CraMetrics.rowCorner, cornerHeight: CraMetrics.rowCorner, transform: nil)
+ }
}
func applyDecor(_ d: DropDecor, animated: Bool) {
@@ -747,14 +762,7 @@ final class TabRowView: SidebarRowView, ArcTooltipTarget, NSTextFieldDelegate {
override func refreshBackground() {
super.refreshBackground()
- let lifted = model?.highlighted == true && !colors.isDark && decor.combine == nil
- layer?.shadowOpacity = lifted ? 0.06 : 0
- if lifted {
- layer?.shadowColor = NSColor.black.cgColor
- layer?.shadowRadius = 3
- layer?.shadowOffset = CGSize(width: 0, height: -1)
- layer?.shadowPath = CGPath(roundedRect: fillRect, cornerWidth: CraMetrics.rowCorner, cornerHeight: CraMetrics.rowCorner, transform: nil)
- }
+ setLifted(model?.highlighted == true)
}
override func hoverChanged() {
@@ -895,9 +903,6 @@ final class TabRowView: SidebarRowView, ArcTooltipTarget, NSTextFieldDelegate {
f.frame = NSRect(x: x - SidebarText.inset, y: (h - fh) / 2, width: max(0, bounds.width - 6 - x + SidebarText.inset), height: fh)
}
focusRing?.frame = fillRect
- if layer?.shadowOpacity ?? 0 > 0 {
- layer?.shadowPath = CGPath(roundedRect: fillRect, cornerWidth: CraMetrics.rowCorner, cornerHeight: CraMetrics.rowCorner, transform: nil)
- }
}
// MARK: Rename
@@ -1182,6 +1187,8 @@ struct SplitRowModel: Equatable {
var depth: Int
var today: Bool
var selected: Bool
+ /// Filled as the open row; not while the ⌘T bar's New Tab row stands in for it.
+ var highlighted: Bool
var focusRing: Bool
var cells: [Cell]
}
@@ -1235,19 +1242,12 @@ final class SplitRowView: SidebarRowView {
override func baseFill() -> NSColor {
guard let m = model else { return .clear }
- return m.selected ? colors.selectedFill : (isHovered ? colors.hoverFill : .clear)
+ return m.highlighted ? colors.selectedFill : (isHovered ? colors.hoverFill : .clear)
}
override func refreshBackground() {
super.refreshBackground()
- let lifted = model?.selected == true && !colors.isDark && decor.combine == nil
- layer?.shadowOpacity = lifted ? 0.06 : 0
- if lifted {
- layer?.shadowColor = NSColor.black.cgColor
- layer?.shadowRadius = 3
- layer?.shadowOffset = CGSize(width: 0, height: -1)
- layer?.shadowPath = CGPath(roundedRect: fillRect, cornerWidth: CraMetrics.rowCorner, cornerHeight: CraMetrics.rowCorner, transform: nil)
- }
+ setLifted(model?.highlighted == true)
}
override func hoverChanged() {
@@ -1475,8 +1475,19 @@ final class NewTabRowView: SidebarRowView {
required init?(coder: NSCoder) { fatalError() }
+ /// While the ⌘T bar is open Arc draws this row as the open one: the selected tab's fill,
+ /// shadow and text.
+ private var active = false
+
+ func apply(active: Bool) {
+ guard active != self.active else { return }
+ self.active = active
+ refreshColors()
+ refreshBackground()
+ }
+
private func refreshColors() {
- let c = isHovered ? colors.textPrimary : colors.textSecondary
+ let c = isHovered || active ? colors.textPrimary : colors.textSecondary
plus.contentTintColor = c
label.textColor = c
}
@@ -1486,7 +1497,12 @@ final class NewTabRowView: SidebarRowView {
refreshColors()
}
- override func baseFill() -> NSColor { isHovered ? colors.selectedFill : .clear }
+ override func baseFill() -> NSColor { isHovered || active ? colors.selectedFill : .clear }
+
+ override func refreshBackground() {
+ super.refreshBackground()
+ setLifted(active)
+ }
override func hoverChanged() {
super.hoverChanged()
diff --git a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
index ec35bfa..568aea7 100644
--- a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
@@ -29,7 +29,7 @@ final class SpaceListView: NSView, NSDraggingSource {
case liveStatus(LiveStatusModel)
case placeholder(active: Bool)
case divider(hasToday: Bool)
- case newTab
+ case newTab(active: Bool)
}
struct Row {
@@ -80,6 +80,8 @@ final class SpaceListView: NSView, NSDraggingSource {
private var scrolling = false
private var scrollRest: Task<Void, Never>?
private var lastRenaming: UUID?
+ /// The active row at the last build: a change scrolls the new one into view.
+ private var lastActive: RowKey?
let autoscroller = DragAutoscroller()
private static let all = NSHashTable<SpaceListView>.weakObjects()
@@ -197,6 +199,8 @@ final class SpaceListView: NSView, NSDraggingSource {
let capturing = ui.capturingTabIDs
let audible = ui.audibleTabIDs
let refreshing = LiveFolderManager.shared.refreshing
+ // The ⌘T bar's New Tab row takes the selection's fill while it is open.
+ let placeholder = showsNewTab && ui.newTabPlaceholderActive && store.focusedSpaceID(window: window) == spaceID
var out: [Row] = []
func icon(_ key: String?) -> (NSImage?, Bool) {
@@ -224,7 +228,7 @@ final class SpaceListView: NSView, NSDraggingSource {
}
func add(_ item: SidebarItem, depth: Int, pinned: Bool, parent: UUID, index: Int) {
- var row = Row(key: .item(item.id), content: .newTab, decor: decor(item.id), itemID: item.id, parent: parent, index: index, depth: depth)
+ var row = Row(key: .item(item.id), content: .newTab(active: false), decor: decor(item.id), itemID: item.id, parent: parent, index: index, depth: depth)
if item.isFolder {
let expanded = store.isExpanded(item.id)
let glyph = palette.folderColors(item.folderIcon)
@@ -254,7 +258,7 @@ final class SpaceListView: NSView, NSDraggingSource {
renameText: item.title ?? item.displayTitle, subtitle: Self.subtitle(tab, navigatedAway: navigatedAway),
icon: img, flipIcon: flip, githubMark: tab.liveItemURL != nil && tab.customIconKey == nil,
editing: renaming == item.id, selected: selected,
- highlighted: picks.isEmpty ? selected : picks.contains(item.id),
+ highlighted: picks.isEmpty ? selected && !placeholder : picks.contains(item.id),
capturing: capturing.contains(item.id), audible: audible.contains(item.id), muted: tab.muted, unread: item.isUnread,
navigatedAway: navigatedAway,
closeGroup: picks.contains(item.id) && picks.count > 1 ? picks.count : 1,
@@ -266,9 +270,9 @@ final class SpaceListView: NSView, NSDraggingSource {
let (img, flip) = icon(c.tab?.iconKey)
return .init(id: c.id, title: c.displayTitle, icon: img, flipIcon: flip)
}
+ let selected = children.contains { store.isSelected($0.id, window: window) }
row.content = .split(SplitRowModel(
- id: item.id, depth: depth, today: !pinned,
- selected: children.contains { store.isSelected($0.id, window: window) },
+ id: item.id, depth: depth, today: !pinned, selected: selected, highlighted: selected && !placeholder,
focusRing: focusID.map { f in children.contains { $0.id == f } } ?? false,
cells: cells))
out.append(row)
@@ -291,11 +295,11 @@ final class SpaceListView: NSView, NSDraggingSource {
let todayKids = store.item(space.todayContainerID)?.children ?? []
out.append(Row(key: .divider, content: .divider(hasToday: !todayKids.isEmpty)))
let atTop = store.settings.newTabButtonAtTop
- if atTop && showsNewTab { out.append(Row(key: .newTab, content: .newTab)) }
+ if atTop && showsNewTab { out.append(Row(key: .newTab, content: .newTab(active: placeholder))) }
for item in store.children(of: space.todayContainerID) {
add(item, depth: 0, pinned: false, parent: space.todayContainerID, index: todayKids.firstIndex(of: item.id) ?? 0)
}
- if !atTop && showsNewTab { out.append(Row(key: .newTab, content: .newTab)) }
+ if !atTop && showsNewTab { out.append(Row(key: .newTab, content: .newTab(active: placeholder))) }
return Built(rows: out, pinnedCount: pinnedCount, palette: palette,
highlightPinned: section == .pinned && !pinnedItems.isEmpty, highlightToday: section == .today,
line: drop?.line)
@@ -344,6 +348,7 @@ final class SpaceListView: NSView, NSDraggingSource {
}
private func apply(_ b: Built) {
+ let wasSynced = synced
palette = b.palette
(scrollView.verticalScroller as? SidebarScroller)?.isDarkTheme = b.palette.isDark
let newColors = SidebarColors(b.palette)
@@ -393,6 +398,7 @@ final class SpaceListView: NSView, NSDraggingSource {
if let h = hovered, h.superview == nil || gone.contains(h) { hovered = nil }
refreshHover()
scrollToRenaming()
+ if wasSynced { revealActiveRow() } else { lastActive = activeRowKey() }
updateJumpPill(animated: synced)
}
@@ -428,7 +434,7 @@ final class SpaceListView: NSView, NSDraggingSource {
case .liveStatus(let m): (v as? LiveStatusRowView)?.apply(m)
case .placeholder(let active): (v as? PinPlaceholderRowView)?.apply(active: active)
case .divider(let hasToday): (v as? DividerRowView)?.apply(hasToday: hasToday)
- case .newTab: break
+ case .newTab(let active): (v as? NewTabRowView)?.apply(active: active)
}
}
@@ -693,6 +699,50 @@ final class SpaceListView: NSView, NSDraggingSource {
}
}
+ /// The row standing for what is open: the ⌘T bar's New Tab row, else the selected tab's
+ /// row or its split's. A tab in a closed folder has none (Arc leaves the list alone then).
+ private func activeRowKey() -> RowKey? {
+ for row in rows {
+ switch row.content {
+ case .newTab(active: true): return row.key
+ case .tab(let m) where m.selected: return row.key
+ case .split(let m) where m.selected: return row.key
+ default: continue
+ }
+ }
+ return nil
+ }
+
+ /// Arc 1.171 (1 Nov 2026) brings whatever becomes active into view, whatever made it so: ⌘T's
+ /// New Tab row, the tab a commit opens, the tab Escape goes back to, Next Tab, a tab picked
+ /// anywhere. It scrolls as little as shows the whole row, which lands on the top or bottom
+ /// edge, and not at all when the row already shows, so a scroll by hand stays put.
+ private func revealActiveRow() {
+ let key = activeRowKey()
+ defer { lastActive = key }
+ guard let key, key != lastActive, showsNewTab, ui.listDrop == nil,
+ let row = rows.first(where: { $0.key == key }) else { return }
+ let clip = scrollView.contentView
+ let visible = clip.bounds
+ guard visible.height > 0 else { return }
+ var y: CGFloat
+ if row.frame.minY < visible.minY { y = row.frame.minY } else if row.frame.maxY > visible.maxY { y = row.frame.maxY - visible.height } else { return }
+ y = min(max(0, y), max(0, document.frame.height - visible.height))
+ guard abs(y - visible.minY) > 0.5 else { return }
+ guard window != nil else {
+ clip.setBoundsOrigin(NSPoint(x: 0, y: y))
+ scrollView.reflectScrolledClipView(clip)
+ return
+ }
+ NSAnimationContext.runAnimationGroup { ctx in
+ ctx.duration = SidebarListMetrics.duration
+ ctx.timingFunction = SidebarListMetrics.timing
+ clip.animator().setBoundsOrigin(NSPoint(x: 0, y: y))
+ } completionHandler: { [weak self] in
+ MainActor.assumeIsolated { self?.scrollView.reflectScrolledClipView(clip) }
+ }
+ }
+
// MARK: Hover
func pointerMoved(_ event: NSEvent?) {
diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swift
index cc01482..ff3d3cf 100644
--- a/Sources/Cra/UI/SidebarUIState.swift
+++ b/Sources/Cra/UI/SidebarUIState.swift
@@ -10,6 +10,9 @@ final class SidebarUIState {
/// The browser window this sidebar belongs to (its space and open tab, see WindowSession).
@ObservationIgnored var windowID = UUID()
var renamingID: UUID?
+ /// The ⌘T bar is open for a new tab: the focused space's New Tab row is the active row,
+ /// filled like the selected tab, which loses its fill (Arc: isCommandBarNewTabPlaceholderActive).
+ var newTabPlaceholderActive = false
var draggingID: UUID?
var hoveredTabID: UUID?
/// Loading progress per tab (0...1), fed by the browser manager.
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 0a01e48..bf0aa7d 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -1856,6 +1856,9 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
commandBar.highlight = focusedSpace.theme.palette.commandHighlight
commandBar.focusedSpaceID = focusedSpaceID
commandBar.open(mode: effectiveMode, prefill: prefill)
+ // Arc draws the New Tab row as the active one while the bar makes a new tab; the
+ // sidebar scrolls to it (SpaceListView.revealActiveRow).
+ sidebarUI.newTabPlaceholderActive = effectiveMode == .newTab && !fillingEmptyPane
// Always centred in the window, also when opened from the toolbar.
commandBar.attached = false
commandBar.panelWidth = min(CraMetrics.commandBarWidth, window.frame.width - 80)
@@ -1898,6 +1901,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
private func hideCommandPanel() {
+ sidebarUI.newTabPlaceholderActive = false
if commandPanel.parent != nil { window?.removeChildWindow(commandPanel) }
let panel = commandPanel!
// Let CommandBarView's fade-out (0.08 s) play before the panel goes away.
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 4d4eda8..f019c06 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -1877,3 +1877,30 @@ pipeline) light vibrant themes are unchanged, solid themes are unchanged over bl
white, closer to Arc's formula: at #4F7CAC, intensity 0.5, Arc predicts 147/163/184 over white, 0.1.23 measured
153/168/188, now 146/161/181. Cra's solid sidebar still darkens ~12 levels from top to bottom in both builds
where Arc's is flat [U].
+
+## The sidebar follows the active row (Arc 1.171, 1 Nov 2026, issue #47, offline Arc + AX row frames + 120 fps)
+
+- [S] Swift field names: the space list's view store has `isCommandBarNewTabPlaceholderActive` (next to
+ `isPulsingNewTabButton`); window state has `sidebarScrollToItemRequest` (`SidebarScrollToItemRequest`),
+ `isDismissingCommandBarViaNewTabSelection`, `mousedownSelectionRevertItem`. Tabs menu: "Reveal Tab in Sidebar"
+ (no shortcut). Arc's only setting here is `newTabsAtStart`; it has no "New Tab button above tabs".
+- [O] Offline Arc (fake home as in "One space") with Victor's sidebar plus 40 Today tabs; row frames sampled
+ over AX every 4 ms (`sidebarAllTabList` rows, 41 pt pitch, list viewport 899 pt), keys posted to Arc's pid.
+- [O] The New Tab row is the first row of Today, right under the divider.
+- [O] ⌘T: while the bar is open the New Tab row is drawn as the open row (selected fill, shadow, primary ink) and
+ the selected tab loses its fill; Escape gives it back. The list scrolls to the New Tab row only when it isn't
+ wholly in view: from the bottom of the list it ended exactly at the top edge of the viewport; with the row in
+ view at the bottom nothing moved (Arc's round ↓ jump button then sat over it, pointing at the selected tab).
+- [O] Whatever becomes the open row is brought into view the same way: the tab a commit opens, the tab Escape
+ goes back to, Next Tab (⌘⌥↓). As little as shows the whole row: a row above the viewport lands on its top edge,
+ one below on its bottom edge (41 pt scroll for a row just below). A row already in view never moves the list,
+ also when it sits under 41 pt from an edge. One commit scrolled 64 pt where 23 would have done [U].
+- [O] A tab inside a closed folder is not revealed (the folder row doesn't stand in): Escape left the list alone.
+- [O] Motion (120 fps recording of ⌘T from the bottom, ~1000 pt): most of the way in the first frame, then
+ steadily smaller steps, still after ~0.22 s; the New Tab row arrives already filled.
+- Cra: `SpaceListView.revealActiveRow` runs after every rebuild and scrolls when the active row's key changed
+ (`activeRowKey`: the active New Tab row, else the selected tab's or split's row), with SidebarListMetrics'
+ 0.22 s snappy curve; `SidebarUIState.newTabPlaceholderActive` is set by `MainWindowController.openCommandBar`
+ for a new-tab bar (not ⌘L, not an empty split pane) and cleared when the bar closes, before a commit selects
+ its tab. Settings ▸ Tabs "Show the New Tab button above tabs" defaults on; settings saved by 0.1.15–0.1.23
+ (always off) move to on once (`newTabButtonDefaultMigrated`).