small improvements

This commit is contained in:
delli 2026-04-21 23:54:51 +02:00
commit f7fbb81d36
16 changed files with 834 additions and 49 deletions

View file

@ -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) {

View file

@ -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 }) {

View file

@ -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