Implement the hybrid clipboard with deferred cut
⌘X/⌘C/⌘V for cards and lanes per 04-interactions.md § Clipboard: - ClipboardStore stages full folder snapshots eagerly at the gesture into Application Support (at most the current copy; sweep at launch and on each copy purges what the pasteboard no longer references; a copy made before quitting pastes whole after restart) and writes the pasteboard a JSON manifest — every entry embedding its index.md, lane entries their cards' too — plus plain-text titles. - Cut is Finder-style deferred: items dim in place off pendingCut, void on pasteboard takeover (changeCount, no timers), source-board close, or per-item external tombstoning; the first armed paste moves the surviving originals whole (tombstoned interior cards land in the destination's trash), a second paste materializes copies from staging. - Paste anchors by the shared flatten-order rule (NewCardTarget's anchor, extracted); a tombstoned selection never anchors; lane paste reaches the right end and stays enabled on a zero-lane board; paste into the source board is the within-board lane duplicate; copies keep created, take fresh GUIDs, and strip tombstoned cards; trash-sourced copies strip deleted: at materialization; ⌘X is disabled on the trash side. - A degraded paste is loud, never silent: staging gone → the embedded index.md fallback lands content-intact, attachments absent, and a BannerCenter-phrased row names what was lost. - The standard Edit items validate through conditionally-attached onCommand handlers, so AppKit's enablement mirrors the availability predicates; text fields keep their own clipboard while focused. 879 unit tests (68 new). Claude-Session: https://claude.ai/code/session_01SR4XGjmBE16ZUYWpfFHXwY
This commit is contained in:
@@ -30,6 +30,10 @@ import SwiftUI
|
||||
/// outward, and Select All. The chorded commands are the menu's (`BoardCommands`); everything
|
||||
/// here is a plain key or a grammar modifier, which is exactly the split 04-interactions.md ▸
|
||||
/// Configurable bindings draws between what remaps and what does not.
|
||||
/// - **The standard Edit items the board answers as a responder** — Select All, and Cut/Copy/Paste
|
||||
/// beside it (`ClipboardCommands.swift`). They are not menu items of ours: the Edit menu already
|
||||
/// carries those titles, and titles are the remapping mechanism's key, so a second row sharing one
|
||||
/// is ruled out (04-interactions.md ▸ Configurable bindings).
|
||||
///
|
||||
/// - **The trash quasi-lane** — trailing, one fixed unit, joining and leaving the width division as
|
||||
/// View ▸ Show Trash toggles it (`TrashLaneView`, 03-board-ui.md § Trash).
|
||||
@@ -179,6 +183,11 @@ struct BoardView: View {
|
||||
// forbids outright (04 ▸ Configurable bindings). A focused text field consumes it first, so
|
||||
// ⌘A inside an inline editor stays text selection with no guard needed here.
|
||||
.onCommand(#selector(NSText.selectAll(_:))) { store.selectAll() }
|
||||
// **Cut / Copy / Paste** (04-interactions.md ▸ Clipboard), through the same responder door
|
||||
// Select All above uses and for the same titles-are-API reason. Each handler is attached only
|
||||
// while its command applies, which is what makes AppKit's automatic enablement mirror the
|
||||
// validation exactly — see `boardClipboardCommands`.
|
||||
.boardClipboardCommands(store: store, clipboard: appModel.clipboard)
|
||||
// **Belt** for a session SwiftUI does report ending: immediate cleanup, gated on the physical
|
||||
// mouse button being up. A finished session's phase events can arrive *after* the user has
|
||||
// started the next drag, and an ungated handler would wipe the new session's state — no
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - The Edit menu's clipboard row
|
||||
|
||||
/// Edit ▸ Cut / Copy / Paste (⌘X / ⌘C / ⌘V) on the board — 11-command-nexus.md's Edit row, whose
|
||||
/// scope is "Board window: cards and lanes … in the trash, ⌘C copy-out only (card and lane entries),
|
||||
/// ⌘X disabled … text editors: standard text clipboard".
|
||||
///
|
||||
/// ### Why this is a responder answer and not three menu items
|
||||
///
|
||||
/// **Select All's precedent, exactly** (`BoardView`): the standard Edit menu already carries these
|
||||
/// three, and AppKit dispatches `cut:`/`copy:`/`paste:` down the responder chain, so the board
|
||||
/// answers them as a responder. Adding items of our own would put a second "Copy"-titled row in the
|
||||
/// menus, which titles-are-API forbids outright (04-interactions.md ▸ Configurable bindings) — a
|
||||
/// custom binding is stored against a title, and two rows sharing one would be ambiguous.
|
||||
///
|
||||
/// ### Availability is the handler's presence
|
||||
///
|
||||
/// `onCommand(_:perform:)` takes an **optional** action, and a `nil` action means the view does not
|
||||
/// respond to that selector at all — which is precisely what AppKit's automatic menu validation
|
||||
/// reads. So attaching the handler conditionally *is* the validation: there is one condition per
|
||||
/// command, it decides both whether the item is enabled and whether the gesture does anything, and
|
||||
/// the two can never disagree because they are the same expression.
|
||||
///
|
||||
/// The conditions themselves live on `ClipboardStore` (`canCopy`/`canCut`/`canPaste`), beside the
|
||||
/// gestures they gate, for the reason every rule in this codebase that can be a named predicate is
|
||||
/// one: an item that is going to no-op should not look available.
|
||||
///
|
||||
/// ### The focused-editor rule, twice over
|
||||
///
|
||||
/// A focused text field consumes these selectors natively, so ⌘X/⌘C/⌘V inside an inline title editor
|
||||
/// stay text operations without anything here doing the arithmetic. The predicates still refuse while
|
||||
/// an editor is open (04 ▸ Grammar: "board-scoped menu commands … disable via menu validation"),
|
||||
/// which is belt over braces — but a board command that stayed armed under an editor is exactly the
|
||||
/// fall-through 04's fixed grammar is careful to rule out.
|
||||
extension View {
|
||||
|
||||
/// Attaches the board's clipboard responders, each only while its command applies.
|
||||
func boardClipboardCommands(store: BoardStore, clipboard: ClipboardStore) -> some View {
|
||||
self
|
||||
.onCommand(#selector(NSText.cut(_:)), perform: clipboard.canCut(from: store) ? {
|
||||
clipboard.cut(from: store)
|
||||
} : nil)
|
||||
.onCommand(#selector(NSText.copy(_:)), perform: clipboard.canCopy(from: store) ? {
|
||||
clipboard.copy(from: store)
|
||||
} : nil)
|
||||
.onCommand(#selector(NSText.paste(_:)), perform: clipboard.canPaste(into: store) ? {
|
||||
clipboard.paste(into: store)
|
||||
} : nil)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - The deferred cut's treatment
|
||||
|
||||
extension View {
|
||||
|
||||
/// **Cut items dim in place until paste moves them** (04-interactions.md ▸ Clipboard).
|
||||
///
|
||||
/// The same reduced opacity a trash row wears while it is being dragged, and for the same reason:
|
||||
/// the item is still there, still selectable, still the user's — it is simply spoken for. A cut
|
||||
/// item is deliberately *not* lifted out of the layout the way a dragged one is; a Finder-style
|
||||
/// deferred cut promises the board looks unchanged until the paste lands.
|
||||
///
|
||||
/// Membership is read straight off `TransientBoardState.pendingCut`, which is where the rules
|
||||
/// already live: a reload ejects a tombstoned or vanished member (so a deleted cut card undims by
|
||||
/// itself), and `ClipboardStore` clears the set outright when the cut is consumed or voided.
|
||||
func cutTreatment(of id: ItemID, in store: BoardStore) -> some View {
|
||||
opacity(store.transient.pendingCut.ids.contains(id) ? ClipboardTreatment.dimmedOpacity : 1)
|
||||
}
|
||||
}
|
||||
|
||||
/// The one number the cut's treatment is (03-board-ui.md § Motion keeps every duration and curve in
|
||||
/// `Motion`; this is neither, but it is the same "no literal at a call site" rule applied to the one
|
||||
/// value three views share).
|
||||
enum ClipboardTreatment {
|
||||
static let dimmedOpacity: Double = 0.45
|
||||
}
|
||||
@@ -27,8 +27,8 @@ import SwiftUI
|
||||
/// ### What is still a later card's
|
||||
///
|
||||
/// The search-aware filtering behind the count belongs to a later milestone. The card face is real
|
||||
/// (`CardFaceView`); what it still owes is the cut treatment and the sole-selected card's attachment
|
||||
/// carousel.
|
||||
/// (`CardFaceView`) and wears the deferred cut's dim (`cutTreatment`); what it still owes is the
|
||||
/// sole-selected card's attachment carousel.
|
||||
struct LaneView: View {
|
||||
|
||||
let store: BoardStore
|
||||
@@ -97,6 +97,9 @@ struct LaneView: View {
|
||||
}
|
||||
.background(selectionBackground)
|
||||
.overlay(selectionStroke)
|
||||
// The deferred cut's dim (04-interactions.md ▸ Clipboard) — on the whole lane, because a cut
|
||||
// lane is cut cards and all.
|
||||
.cutTreatment(of: lane.id, in: store)
|
||||
.onGeometryChange(for: CGFloat.self) { $0.size.height } action: { measuredHeight = $0 }
|
||||
// **This lane's drop target**, on the whole body. It accepts *every* session type and routes
|
||||
// internally — card sessions against this lane's masonry zones, lane sessions forwarded to
|
||||
@@ -746,6 +749,9 @@ private struct CardFaceView: View {
|
||||
lineWidth: isFileHovered ? 2.5 : 1.5
|
||||
)
|
||||
)
|
||||
// The deferred cut's dim (04-interactions.md ▸ Clipboard: "cut items dim in place until paste
|
||||
// moves them"). Above `contentShape` so the face stays fully clickable while it waits.
|
||||
.cutTreatment(of: card.id, in: store)
|
||||
.contentShape(Rectangle())
|
||||
// **Clicking never edits** (04-interactions.md ▸ Selection, a pivot from the pathfinder's
|
||||
// two-stage Finder rename): one click selects and that is all it does — no timer, no
|
||||
|
||||
@@ -56,31 +56,12 @@ enum NewCardTarget {
|
||||
let lanes = snapshot.lanes.filter { !$0.isDeleted }
|
||||
guard !lanes.isEmpty else { return nil }
|
||||
|
||||
if selection.liveness == .live, !selection.ids.isEmpty {
|
||||
// The last selected member in flatten order — lane `order`, then card `order`, the
|
||||
// multi-drag order (04, settled; the same anchor serves paste). The snapshot's lanes
|
||||
// and cards are already in display order, so the flatten order is one walk, and the
|
||||
// *last* hit is the anchor. Selection is homogeneous (cards XOR lanes), so only one of
|
||||
// the two branches ever fires within a walk; a sole selection is simply the degenerate
|
||||
// one-member case of the same rule.
|
||||
var anchor: Resolution?
|
||||
for lane in lanes {
|
||||
// A selected lane: creation appends at its bottom, Return consistency.
|
||||
if selection.ids.contains(lane.id) {
|
||||
anchor = Resolution(laneID: lane.id, anchorCardID: nil)
|
||||
}
|
||||
// A selected card: its lane, immediately after it — paste-anchor consistency.
|
||||
for card in lane.cards where !card.isDeleted && selection.ids.contains(card.id) {
|
||||
anchor = Resolution(laneID: lane.id, anchorCardID: card.id)
|
||||
}
|
||||
}
|
||||
if let anchor { return anchor }
|
||||
// The ids name nothing the board renders — a selection the next reload will drop.
|
||||
// Falls through to the last-active lane rather than refusing: the user pressed ⌘N and
|
||||
// the board has lanes.
|
||||
if let anchor = flattenAnchor(selection: selection, snapshot: snapshot) {
|
||||
return anchor
|
||||
}
|
||||
|
||||
// Nothing selected, a tombstoned selection, or a stale one: the lane that most recently
|
||||
// Nothing selected, a tombstoned selection, or a stale one — the ids name nothing the board
|
||||
// renders, a selection the next reload will drop. Falls through rather than refusing: the
|
||||
// user pressed ⌘N and the board has lanes. The target is then the lane that most recently
|
||||
// held selection or a creation, and the first lane when there is no such lane (or it has
|
||||
// since gone).
|
||||
if let lastActiveLaneID, let lane = lanes.first(where: { $0.id == lastActiveLaneID }) {
|
||||
@@ -88,4 +69,41 @@ enum NewCardTarget {
|
||||
}
|
||||
return lanes.first.map { Resolution(laneID: $0.id, anchorCardID: nil) }
|
||||
}
|
||||
|
||||
/// **The shared anchor, on its own** — "a multi-selection anchors at its last member in flatten
|
||||
/// order (lane `order`, then card `order`, the multi-drag order; the same anchor serves paste)".
|
||||
///
|
||||
/// Extracted rather than left inside `resolve` because paste needs *exactly this clause* and not
|
||||
/// the two that surround it. Card paste is `resolve` verbatim (the last-active-lane fallback and
|
||||
/// all), but **lane paste has a different fallback** — "nothing selected = the board's right end",
|
||||
/// never the last-active lane — so it takes the anchor and stops. Two derivations of "the last
|
||||
/// member in flatten order" would be two chances for creation and paste to disagree about the one
|
||||
/// rule 04 says they share.
|
||||
///
|
||||
/// `nil` covers the three cases that anchor nothing, which the callers then answer their own way:
|
||||
/// an empty selection, a **tombstoned** one ("a tombstoned selection never anchors paste",
|
||||
/// settled — and "a trashed card's live disk-lane never leaks in as 'the selected card's lane'",
|
||||
/// which falls out of never looking at the trashed side at all), and a stale one whose ids name
|
||||
/// nothing the board renders.
|
||||
static func flattenAnchor(selection: ItemReferenceSet, snapshot: BoardModel) -> Resolution? {
|
||||
guard selection.liveness == .live, !selection.ids.isEmpty else { return nil }
|
||||
|
||||
// The snapshot's lanes and cards are already in display order, so the flatten order is one
|
||||
// walk, and the *last* hit is the anchor. Selection is homogeneous (cards XOR lanes), so only
|
||||
// one of the two branches ever fires within a walk; a sole selection is simply the degenerate
|
||||
// one-member case of the same rule.
|
||||
var anchor: Resolution?
|
||||
for lane in snapshot.lanes where !lane.isDeleted {
|
||||
// A selected lane: creation appends at its bottom, Return consistency; paste lands after
|
||||
// the lane itself.
|
||||
if selection.ids.contains(lane.id) {
|
||||
anchor = Resolution(laneID: lane.id, anchorCardID: nil)
|
||||
}
|
||||
// A selected card: its lane, immediately after it — paste-anchor consistency.
|
||||
for card in lane.cards where !card.isDeleted && selection.ids.contains(card.id) {
|
||||
anchor = Resolution(laneID: lane.id, anchorCardID: card.id)
|
||||
}
|
||||
}
|
||||
return anchor
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/// Where ⌘V lands (04-interactions.md ▸ Clipboard), as pure functions of the selection, the
|
||||
/// last-active lane, and the snapshot (`PasteTargetTests`).
|
||||
///
|
||||
/// The two rules verbatim, and each clause's branch below:
|
||||
///
|
||||
/// > Paste lands after the anchor card (or appends to a selected lane); a multi-selection anchors at
|
||||
/// > its last member in flatten order — the ⌘N target rule's shared anchor. … **A tombstoned
|
||||
/// > selection never anchors paste**: ⌘V stays enabled and behaves exactly as with nothing selected —
|
||||
/// > a card payload appends to the last-active lane, a lane payload lands at the board's right end.
|
||||
///
|
||||
/// > **Lane paste** lands after the anchor lane — the selected lane, or the selected card's lane
|
||||
/// > (several selected: the last, per the shared anchor rule); nothing selected = the board's right
|
||||
/// > end.
|
||||
///
|
||||
/// Plus 04 ▸ The map's zero-lane clause: "New Card, Return-creation, and Paste with a *card* payload
|
||||
/// disable via menu validation until a lane exists … Paste with a **lane** payload … stays enabled
|
||||
/// and lands at the board's right end".
|
||||
///
|
||||
/// **Pure, for `NewCardTarget`'s reason** — the branches become lines of test rather than gestures to
|
||||
/// drive, and the menu item's `disabled` reads the *same* answer as the paste's own target rather
|
||||
/// than a second, hand-kept-in-sync condition.
|
||||
///
|
||||
/// ### What it deliberately reuses
|
||||
///
|
||||
/// The anchor is `NewCardTarget.flattenAnchor`, not a second walk: 04 says creation and paste share
|
||||
/// one anchor ("the ⌘N target rule's shared anchor"), and two derivations of "the last member in
|
||||
/// flatten order" would be two chances for them to disagree. The card branch goes further and reuses
|
||||
/// `NewCardTarget.resolve` whole, because a card paste's *fallback* is the ⌘N rule's fallback too —
|
||||
/// the last-active lane, then the first lane. Only the lane branch stops at the anchor, because its
|
||||
/// fallback is the board's right end instead.
|
||||
enum PasteTarget {
|
||||
|
||||
/// Where a card payload lands: which lane, and the position among that lane's rendered cards.
|
||||
struct Cards: Equatable {
|
||||
let laneID: ItemID
|
||||
/// A position in the lane's logical card order, counted among what it renders *now* — the
|
||||
/// convention every arrival path here takes (`BoardStore.receiveCards`).
|
||||
let index: Int
|
||||
}
|
||||
|
||||
/// The card payload's target, or `nil` on a **zero-lane board** — which is therefore the menu
|
||||
/// item's `disabled` condition as well as the paste's refusal, so the two cannot disagree.
|
||||
static func cards(
|
||||
selection: ItemReferenceSet,
|
||||
lastActiveLaneID: ItemID?,
|
||||
snapshot: BoardModel
|
||||
) -> Cards? {
|
||||
guard let resolution = NewCardTarget.resolve(
|
||||
selection: selection,
|
||||
lastActiveLaneID: lastActiveLaneID,
|
||||
snapshot: snapshot
|
||||
),
|
||||
let lane = snapshot.lanes.first(where: { $0.id == resolution.laneID && !$0.isDeleted })
|
||||
else { return nil }
|
||||
|
||||
let rendered = lane.cards.filter { !$0.isDeleted }
|
||||
// `insertionIndex` answers `nil` for "append", which is `rendered.count` — the same position
|
||||
// said two ways, and the creation path's own degradation for an anchor that has since gone.
|
||||
let index = BoardStore.insertionIndex(after: resolution.anchorCardID, among: rendered) ?? rendered.count
|
||||
return Cards(laneID: lane.id, index: index)
|
||||
}
|
||||
|
||||
/// The lane payload's slot among the board's live lanes — **always an answer**, zero-lane board
|
||||
/// included, because lane paste "stays enabled and lands at the board's right end" whatever the
|
||||
/// board holds. That is what makes it the other way out of a board with no lanes.
|
||||
static func lanes(selection: ItemReferenceSet, snapshot: BoardModel) -> Int {
|
||||
let lanes = snapshot.lanes.filter { !$0.isDeleted }
|
||||
guard let anchor = NewCardTarget.flattenAnchor(selection: selection, snapshot: snapshot),
|
||||
let position = lanes.firstIndex(where: { $0.id == anchor.laneID })
|
||||
else {
|
||||
// Nothing selected, a tombstoned selection, or a stale one: the right end.
|
||||
return lanes.count
|
||||
}
|
||||
return position + 1
|
||||
}
|
||||
}
|
||||
@@ -257,7 +257,13 @@ private struct TrashEntryRow: View {
|
||||
rowFace
|
||||
// The row being dragged out dims in place — the source stays visible in the trash,
|
||||
// because a restore is not a removal until the write lands.
|
||||
.opacity(drops.session.isDragging(entry.id) ? 0.45 : 1)
|
||||
.opacity(drops.session.isDragging(entry.id) ? ClipboardTreatment.dimmedOpacity : 1)
|
||||
// The deferred cut wears the same dim wherever it lands, so the treatment is stated for
|
||||
// every surface a `pendingCut` could name rather than for two of the three. In practice
|
||||
// it never fires here: ⌘X is disabled on tombstoned selections (04-interactions.md ▸ The
|
||||
// trash), and a pending cut is homogeneous by liveness — a reload that tombstones a cut
|
||||
// card *ejects* it from the set rather than moving it to the other side.
|
||||
.cutTreatment(of: entry.id, in: store)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture { select() }
|
||||
.marqueeTarget(entry.id, kind: entry.isLaneEntry ? .lane : .card, side: .trashed, in: registry)
|
||||
|
||||
Reference in New Issue
Block a user