Copy Link — a card context-menu row that puts the card folder on the pasteboard
Card 737a949f: "Add an option to card context menu to copy a link to the card folder." Implements the design ruling verbatim. - New context-menu row "Copy Link" (CardFaceView.boardMenu, board side only — trash cards are excluded, matching "sole selected live card"). Writes the clicked card's folder in one pasteboard item carrying two representations: the file:// URL under .fileURL and the plain absolute path under .string (FolderLinkPasteboard.swift). Enabled on a sole selected live card; disabled on a multi-selection and wherever edit-shaped actions already disable, per the ruling. Also exposed as a VoiceOver custom action alongside its siblings. - Menu-bar twin: Board ▸ Copy Link (BoardCommands.swift, CopyLinkCommand), no default chord — the every-function-a-menu-item contract in DESIGN/11-command-nexus.md is still current, so this is the twin that contract calls for, homed the way Open Card/Rename/ Style… already are. - DESIGN/11-command-nexus.md: new Board-menu row and an updated Card context-menu row. - Tests (KanbanTests/CopyLinkTests.swift): the target predicate's enablement (sole card / multi-selection / lane / trash / empty / inline-editing), the pasteboard write's exact bytes via a fake pasteboard (both representations, exact folder URL), and a disabled-target no-op. Caught and fixed during self-review: an early version read the context menu's widened-selection helper (targetIDs) inside the Copy Link row's .disabled(...), which reads store.selection. Since .contextMenu's content closure is evaluated on every ordinary body pass (not only when the menu opens), that resubscribed every card face on the board to every selection change — the exact O(board) regression RENDER-INSTRUMENTATION.md's isSelected/selectedCount split exists to prevent, caught by BoardRenderPerformanceTests and MarqueeRenderCostTests. Fixed by reading the already-hoisted, non-Observable `selectedCount` parameter instead, which answers the same "how many ride along" question at zero extra subscription cost. xcodegen generate, the Kanban scheme build, and the full KanbanTests suite (2816 tests) are clean. Claude-Session: https://claude.ai/code/session_014PtZdPwqZuqEDLc6wZMtEy
This commit is contained in:
@@ -425,6 +425,60 @@ struct BoardInfoCommand: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Copy Link
|
||||
|
||||
extension BoardStore {
|
||||
|
||||
/// Board ▸ Copy Link's target: the sole selected **live board card**'s folder URL, or `nil` — "a
|
||||
/// link is singular" (design ruling 2026-08-09, card 737a949f "Add an option to card context menu
|
||||
/// to copy a link to the card folder"), the same board-card-only shape `openCardTarget` answers
|
||||
/// for its own reason: a lane, a multi-selection and a trash selection all disable it.
|
||||
///
|
||||
/// **Additionally gated on `acceptsBoardMutations`**, unlike `openCardTarget` — the ruling asks
|
||||
/// for this in as many words ("disabled … wherever edit-shaped actions already disable"), even
|
||||
/// though writing a link to the pasteboard changes nothing on disk. Worth flagging rather than
|
||||
/// silently matching: Copy Link could have stayed live under the lock the way Reveal in Finder
|
||||
/// does ("not edit-shaped … inspecting a folder before a purge is exactly the errand it exists
|
||||
/// for" — `CardFaceView.trashMenu`'s doc), but the ruling states the gate explicitly, so it is
|
||||
/// implemented as written rather than re-litigated here (the card's DECISIONS comment flags it).
|
||||
var copyLinkTarget: URL? {
|
||||
guard acceptsBoardMutations else { return nil }
|
||||
guard selection.container == .board, selection.ids.count == 1, let id = selection.ids.first,
|
||||
Self.boardItem(id, in: snapshot)?.cardID != nil
|
||||
else { return nil }
|
||||
return ItemPath.resolve([id], in: .board, snapshot: snapshot).first?.folder(under: rootURL)
|
||||
}
|
||||
|
||||
/// Board ▸ Copy Link's action, and the menu-bar row's one write. The context menu's own Copy Link
|
||||
/// row (`CardFaceView.copyLink`) does not call this: a context menu names its target by where it
|
||||
/// was invoked (`targetIDs`'s standing rule, shared with Style… and Delete), not by the live
|
||||
/// selection this property reads.
|
||||
func copyCardLink(to pasteboard: FolderLinkPasteboard = SystemFolderLinkPasteboard()) {
|
||||
guard let folder = copyLinkTarget else { return }
|
||||
pasteboard.write(link: folder)
|
||||
}
|
||||
}
|
||||
|
||||
/// Board ▸ Copy Link — no default chord (11-command-nexus.md; design ruling 2026-08-09, card
|
||||
/// 737a949f). The menu-bar twin the ruling asks for ("follow the codebase's CURRENT command
|
||||
/// conventions … if the every-function-a-menu-item contract still governs, add the item … in the
|
||||
/// matching menu"): 11-command-nexus.md's contract is still in force, so this exists beside the card
|
||||
/// context menu's own row (`CardFaceView.boardMenu`) rather than instead of it.
|
||||
///
|
||||
/// One answer (`copyLinkTarget`) for both the row's `disabled` state and its action, `BoardRenameCommand`'s
|
||||
/// shape.
|
||||
struct CopyLinkCommand: View {
|
||||
|
||||
@FocusedValue(\.boardStore) private var store
|
||||
|
||||
var body: some View {
|
||||
Button("Copy Link") {
|
||||
store?.copyCardLink()
|
||||
}
|
||||
.disabled(store?.copyLinkTarget == nil)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Rename
|
||||
|
||||
/// Board ▸ Rename — no default chord, deliberately (11-command-nexus.md: "— (cards: Return in
|
||||
|
||||
@@ -27,6 +27,11 @@ import SwiftUI
|
||||
/// so the file-hover highlight is board-only; and the trash's context-menu Delete is *permanent*, so
|
||||
/// it needs the window's confirmation host (11-command-nexus.md ▸ Context menus' Trash cards row).
|
||||
///
|
||||
/// **A fourth board-only row joined 2026-08-09**: Copy Link (design ruling, card 737a949f) — not one
|
||||
/// of the three edit-shaped absences above (it changes nothing on disk), but "sole selected **live**
|
||||
/// card" is its own words for the same board-only scope, so it lives in `boardMenu` only and has no
|
||||
/// trash-side counterpart, absence or otherwise.
|
||||
///
|
||||
/// **Only the trash side carries the confirmation host** (settled): the board side's Delete is the
|
||||
/// ordinary staged move into `.trash/` and never stands an alert, so `board` needs nothing beyond the
|
||||
/// card opener.
|
||||
@@ -596,8 +601,8 @@ struct CardFaceView: View, Equatable {
|
||||
|
||||
// MARK: - Context menus
|
||||
|
||||
/// Open, Rename, Style…, the quick-style recents row, Delete — 11-command-nexus.md ▸ Context
|
||||
/// menus' Card row, in its order.
|
||||
/// Open, Copy Link, Rename, Style…, the quick-style recents row, Delete — 11-command-nexus.md ▸
|
||||
/// Context menus' Card row, in its order.
|
||||
@ViewBuilder
|
||||
private func boardMenu(openCard: @escaping (ItemID) -> Void) -> some View {
|
||||
// Open: Board ▸ Open Card's pointer twin (`OpenCardCommand`), restricted to the clicked card
|
||||
@@ -611,6 +616,13 @@ struct CardFaceView: View, Equatable {
|
||||
openCard(card.id)
|
||||
}
|
||||
|
||||
// Copy Link — design ruling 2026-08-09, card 737a949f: "writes the card FOLDER's file:// URL
|
||||
// to the general pasteboard … enabled on a sole selected live card only; disabled on
|
||||
// multi-selections (a link is singular)". Grouped beside Open, both read-only rows, ahead of
|
||||
// the edit-shaped block below (Board ▸ Copy Link's own doc comment, `CopyLinkCommand`).
|
||||
Button("Copy Link") { copyLink() }
|
||||
.disabled(!copyLinkEnabled)
|
||||
|
||||
Divider()
|
||||
|
||||
// Rename: Board ▸ Rename's exact store path (`BoardRenameCommand`) — `beginRename(of:
|
||||
@@ -641,6 +653,8 @@ struct CardFaceView: View, Equatable {
|
||||
@ViewBuilder
|
||||
private func boardActions(openCard: @escaping (ItemID) -> Void) -> some View {
|
||||
Button("Open") { openCard(card.id) }
|
||||
Button("Copy Link") { copyLink() }
|
||||
.disabled(!copyLinkEnabled)
|
||||
Button("Rename") { beginRename() }
|
||||
.disabled(!store.acceptsBoardMutations)
|
||||
Button("Delete") { deleteTargets() }
|
||||
@@ -698,6 +712,41 @@ struct CardFaceView: View, Equatable {
|
||||
NSWorkspace.shared.activateFileViewerSelecting(targetFolders)
|
||||
}
|
||||
|
||||
/// Copy Link's context-menu enablement — **`selectedCount`, never `targetIDs`**. `targetIDs`
|
||||
/// reads `store.selection` directly, and `.contextMenu`'s content closure is not lazy: SwiftUI
|
||||
/// evaluates `boardMenu` (and therefore any `.disabled(...)` inside it) on every ordinary body
|
||||
/// pass, not only when the menu opens, exactly as building this row against `targetIDs` first
|
||||
/// proved the hard way — every face's body re-ran on every selection change, the precise O(board)
|
||||
/// regression `isSelected`/`selectedCount` exist to prevent (this struct's own top-of-file note;
|
||||
/// `BoardRenderPerformanceTests.selectionStillRepaints`, which caught it).
|
||||
///
|
||||
/// `selectedCount` is the render-safe answer to the same question: the parent (`LaneView`) already
|
||||
/// computes "the size of the selection this face belongs to, else 1" as a **plain, non-Observable
|
||||
/// parameter** — `targetIDs.count`'s exact widening, paid for once per lane instead of once per
|
||||
/// card-menu-construction. "A link is singular" (design ruling 2026-08-09, card 737a949f), so a
|
||||
/// count above 1 disables rather than guessing which member was meant — the same reading Style…
|
||||
/// and Delete's `targetIDs` give their own action, just checked here instead of only inside it,
|
||||
/// because unlike them this row's *enabled state itself* has to say so.
|
||||
private var copyLinkEnabled: Bool {
|
||||
store.acceptsBoardMutations && selectedCount == 1
|
||||
}
|
||||
|
||||
/// Copy Link's write — `copyLinkEnabled`'s one caller. Resolves **this card's own folder**
|
||||
/// directly rather than through `targetIDs`: `copyLinkEnabled == true` already guarantees the
|
||||
/// widened target is `card.id` alone (either this card sits outside the live selection, or it is
|
||||
/// the selection's sole member), so there is no widened set left to read `store.selection` for.
|
||||
/// `store.copyLinkTarget` is deliberately not reused either — that property reads the *live*
|
||||
/// selection for the menu-bar row (`CopyLinkCommand`), which would answer wrongly for a card
|
||||
/// clicked outside the current selection, exactly the case `TrashWriteTests`'
|
||||
/// `contextMenuDeleteIgnoresTheSelection` pins for Delete.
|
||||
private func copyLink() {
|
||||
guard copyLinkEnabled,
|
||||
let folder = ItemPath.resolve([card.id], in: role.container, snapshot: store.snapshot)
|
||||
.first?.folder(under: store.rootURL)
|
||||
else { return }
|
||||
SystemFolderLinkPasteboard().write(link: folder)
|
||||
}
|
||||
|
||||
/// VO-Space's landing: the ⌘-click funnel, on this card, **in this face's container** — so a
|
||||
/// trash card's toggle can no more mix with a board selection than a ⌘-click could.
|
||||
private func toggleSelection() {
|
||||
|
||||
Reference in New Issue
Block a user