mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
small improvements
This commit is contained in:
parent
3684802398
commit
f7fbb81d36
16 changed files with 834 additions and 49 deletions
|
|
@ -113,7 +113,7 @@ final class ShelfItemViewModel: ObservableObject {
|
|||
|
||||
// MARK: - Actions
|
||||
func handleClick(event: NSEvent, view: NSView) {
|
||||
let flags = event.modifierFlags
|
||||
let flags = event.modifierFlags.intersection(.deviceIndependentFlagsMask)
|
||||
if flags.contains(.shift) {
|
||||
selection.shiftSelect(to: item, in: ShelfStateViewModel.shared.items)
|
||||
} else if flags.contains(.command) {
|
||||
|
|
|
|||
|
|
@ -83,6 +83,19 @@ final class ShelfSelectionModel: ObservableObject {
|
|||
lastAnchorID = nil
|
||||
}
|
||||
|
||||
func reconcileSelection(with allItems: [ShelfItem]) {
|
||||
let validIDs = Set(allItems.map(\.id))
|
||||
let filteredSelection = selectedIDs.intersection(validIDs)
|
||||
|
||||
if filteredSelection != selectedIDs {
|
||||
selectedIDs = filteredSelection
|
||||
}
|
||||
|
||||
if let anchor = lastAnchorID, !validIDs.contains(anchor) {
|
||||
lastAnchorID = selectedIDs.first
|
||||
}
|
||||
}
|
||||
|
||||
// Keep anchor sane if items array changed drastically (optional helper)
|
||||
func ensureValidAnchor(in allItems: [ShelfItem]) {
|
||||
if let anchor = lastAnchorID, !allItems.contains(where: { $0.id == anchor }) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,10 @@ final class ShelfStateViewModel: ObservableObject {
|
|||
static let shared = ShelfStateViewModel()
|
||||
|
||||
@Published private(set) var items: [ShelfItem] = [] {
|
||||
didSet { ShelfPersistenceService.shared.save(items) }
|
||||
didSet {
|
||||
ShelfPersistenceService.shared.save(items)
|
||||
ShelfSelectionModel.shared.reconcileSelection(with: items)
|
||||
}
|
||||
}
|
||||
|
||||
@Published var isLoading: Bool = false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue