From 285f21476fc66ca897718ba4347d5a32707dac57 Mon Sep 17 00:00:00 2001 From: momenbasel Date: Wed, 12 Aug 2026 08:45:33 +0300 Subject: [PATCH] Scope clip deletion to the collection on screen Deleting a card from history no longer erases saved pinboard copies, and deleting a pinboard copy no longer reaches into history or other boards, even for legacy clips that share an id across containers. Deleting exactly what was removed also closes an image-file leak: the old cross-container removal could delete entries stored under two different file names while cleaning up only one of them. Extracted from #40 per review; the multi-select work continues there. Co-authored-by: Alvie Stoddard Co-authored-by: Cursor --- Sources/Pesty/Store/ClipboardStore.swift | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Sources/Pesty/Store/ClipboardStore.swift b/Sources/Pesty/Store/ClipboardStore.swift index 150bbc3..31f55bd 100644 --- a/Sources/Pesty/Store/ClipboardStore.swift +++ b/Sources/Pesty/Store/ClipboardStore.swift @@ -116,10 +116,25 @@ final class ClipboardStore { for item in removed { deleteImageFile(item) } } + /// Deletes a clip from the collection currently on screen only. A Pinboard + /// is an independently saved collection: deleting a card from history must + /// not erase saved copies, and deleting a pinboard copy must not touch + /// history or other pinboards, even for legacy clips that share an id. + /// Deleting exactly what was removed also closes an image-file leak: the + /// old cross-container removal deleted entries under two file names but + /// cleaned up only one of them. func delete(_ item: ClipItem) { - history.removeAll { $0.id == item.id } - for i in pinboards.indices { pinboards[i].items.removeAll { $0.id == item.id } } - deleteImageFile(item) + let removed: [ClipItem] + switch source { + case .history: + removed = history.filter { $0.id == item.id } + history.removeAll { $0.id == item.id } + case .pinboard(let boardID): + guard let boardIndex = pinboards.firstIndex(where: { $0.id == boardID }) else { return } + removed = pinboards[boardIndex].items.filter { $0.id == item.id } + pinboards[boardIndex].items.removeAll { $0.id == item.id } + } + for entry in removed { deleteImageFile(entry) } if selectedID == item.id { selectFirst() } scheduleSave() }