8000 Some cleanup by weisJ · Pull Request #841 · p0deje/Maccy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Some cleanup #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Maccy/Observables/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,6 +25,7 @@ class AppState: Sendable {
} else if let item = footer.items.first(where: { $0.id == selection }) {
footer.selectedItem = item
}
scrollTarget = selection
}
}

Expand Down
1 change: 0 additions & 1 deletion Maccy/Observables/History.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class History {
}

updateUnpinnedShortcuts()
AppState.shared.selection = item.id
if (item.isUnpinned) {
AppState.shared.scrollTarget = item.id
}
Expand Down
13 changes: 4 additions & 9 deletions Maccy/Views/HistoryListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
0