diff --git a/Maccy/Observables/AppState.swift b/Maccy/Observables/AppState.swift index d49e76c7..8dfd2ff3 100644 --- a/Maccy/Observables/AppState.swift +++ b/Maccy/Observables/AppState.swift @@ -17,9 +17,6 @@ class AppState: Sendable { var scrollTarget: UUID? var selection: UUID? = nil { didSet { - // Cancel scrolling - scrollTarget = nil - history.selectedItem = nil footer.selectedItem = nil @@ -28,6 +25,7 @@ class AppState: Sendable { } else if let item = footer.items.first(where: { $0.id == selection }) { footer.selectedItem = item } + scrollTarget = selection } } diff --git a/Maccy/Observables/History.swift b/Maccy/Observables/History.swift index 399ae658..5f82eaec 100644 --- a/Maccy/Observables/History.swift +++ b/Maccy/Observables/History.swift @@ -258,7 +258,6 @@ class History { } updateUnpinnedShortcuts() - AppState.shared.selection = item.id if (item.isUnpinned) { AppState.shared.scrollTarget = item.id } diff --git a/Maccy/Views/HistoryListView.swift b/Maccy/Views/HistoryListView.swift index 8700e5b6..6f6e4f4b 100644 --- a/Maccy/Views/HistoryListView.swift +++ b/Maccy/Views/HistoryListView.swift @@ -36,12 +36,14 @@ struct HistoryListView: View { HistoryItemView(item: item) } } - .task(id: appState.selection) { + .task(id: appState.scrollTarget) { + guard appState.scrollTarget != nil else { return } try? await Task.sleep(for: .milliseconds(10)) guard !Task.isCancelled else { return } - if let selection = appState.selection { + if let selection = appState.scrollTarget { proxy.scrollTo(selection) + appState.scrollTarget = nil } } .onChange(of: scenePhase) { @@ -54,13 +56,6 @@ struct HistoryListView: View { modifierFlags.flags = [] } } - .onChange(of: appState.scrollTarget) { - // Recheck if the target has been cleared in the meantime, due to navigation - if let targetId = appState.scrollTarget { - proxy.scrollTo(targetId) - appState.scrollTarget = nil - } - } // Calculate the total height inside a scroll view. .background { GeometryReader { geo in