Skip to content

Commit

Permalink
fix: Ensure newly created cells always show correct selection state (#92
Browse files Browse the repository at this point in the history
)

It seems that the cell layers weren't always being created on cell
creation, meaning that selection display was unreliable.
  • Loading branch information
jbmorley authored Mar 21, 2024
1 parent c3d4792 commit 47fafa2
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions Folders/Views/ShortcutItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,14 @@ class ShortcutItemView: NSCollectionViewItem {
}
}

override func viewDidLoad() {
view.wantsLayer = true
}

func updateState() {
view.layer?.backgroundColor = isSelected || highlightState == .forSelection ? NSColor.controlAccentColor.cgColor : nil
}

// func updateSelectionState() {
// if isSelected {
// // Apply selected appearance
// view.layer?.borderWidth = 2.0
// view.layer?.borderColor = NSColor.blue.cgColor
// } else {
// // Apply non-selected appearance
// view.layer?.borderWidth = 0.0
// }
// }

override var highlightState: NSCollectionViewItem.HighlightState {
didSet {
updateState()
Expand All @@ -67,15 +60,6 @@ class ShortcutItemView: NSCollectionViewItem {
label.isSelectable = false
label.isEditable = false
label.drawsBackground = false

// view.addSubview(label)
// NSLayoutConstraint.activate([
// label.leadingAnchor.constraint(equalTo: view.leadingAnchor),
// label.trailingAnchor.constraint(equalTo: view.trailingAnchor),
// label.topAnchor.constraint(equalTo: view.topAnchor),
// label.bottomAnchor.constraint(equalTo: view.bottomAnchor),
// ])

self.label = label
}

Expand All @@ -94,8 +78,7 @@ class ShortcutItemView: NSCollectionViewItem {

cancel()

let size = CGSize(width: 300, height: 300)
// TODO: Detect the scale?
let size = CGSize(width: 300, height: 300) // TODO: Detect view dimensions and scale.

// Load the image.
let request = QLThumbnailGenerator.Request(fileAt: url,
Expand Down

0 comments on commit 47fafa2

Please sign in to comment.