From f45c2ca83ef21228718f100df94b929e3cccee72 Mon Sep 17 00:00:00 2001 From: Alex Rodionov Date: Wed, 31 Jul 2024 15:04:21 -0700 Subject: [PATCH] Ensure history size cannot grow beyond settings --- Maccy/Observables/History.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Maccy/Observables/History.swift b/Maccy/Observables/History.swift index f94c5bbb..30311bed 100644 --- a/Maccy/Observables/History.swift +++ b/Maccy/Observables/History.swift @@ -120,6 +120,10 @@ class History { @MainActor func add(_ item: HistoryItem) { + while items.filter(\.isUnpinned).count >= Defaults[.size] { + delete(items.last(where: \.isUnpinned)) + } + if let existingHistoryItem = findSimilarItem(item) { if isModified(item) == nil { item.contents = existingHistoryItem.contents