feat: restyle emoji picker with sectioned tiles
This commit is contained in:
@@ -18,7 +18,7 @@ import Testing
|
||||
let grid = try #require(scroll.documentView as? NSCollectionView)
|
||||
let layout = try #require(grid.collectionViewLayout)
|
||||
let first = try #require(layout.layoutAttributesForItem(at: IndexPath(item: 0, section: 0)))
|
||||
let nextRow = try #require((1..<EmojiCatalog.all.count).first { index in
|
||||
let nextRow = try #require((1..<grid.numberOfItems(inSection: 0)).first { index in
|
||||
guard let frame = layout.layoutAttributesForItem(at: IndexPath(item: index, section: 0))?.frame else { return false }
|
||||
return frame.minY > first.frame.minY
|
||||
})
|
||||
@@ -27,3 +27,40 @@ import Testing
|
||||
#expect(pasteboard.string(forType: .string) == EmojiCatalog.all[nextRow].value)
|
||||
print("Emoji grid: \(nextRow) columns at 750 points; down navigation follows the rendered row.")
|
||||
}
|
||||
|
||||
@Test @MainActor func emojiNavigationCrossesFavoritesRecentAndCategorySections() throws {
|
||||
_ = NSApplication.shared
|
||||
let suite = "EmojiSections.\(UUID().uuidString)"
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
let pasteboard = NSPasteboard.withUniqueName()
|
||||
defer { defaults.removePersistentDomain(forName: suite); pasteboard.releaseGlobally() }
|
||||
defaults.set(["👩💻", "🙏"], forKey: "favoriteEmoji")
|
||||
defaults.set(["🚀", "👩💻", "😀"], forKey: "recentEmoji")
|
||||
let picker = EmojiPickerController(defaults: defaults, pasteboard: pasteboard)
|
||||
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 750, height: 400),
|
||||
styleMask: [.borderless], backing: .buffered, defer: false)
|
||||
window.contentView = picker.view
|
||||
picker.view.layoutSubtreeIfNeeded()
|
||||
let scroll = try #require(picker.view.subviews.compactMap { $0 as? NSScrollView }.first)
|
||||
let grid = try #require(scroll.documentView as? NSCollectionView)
|
||||
#expect(grid.numberOfItems(inSection: 0) == 2)
|
||||
#expect(grid.numberOfItems(inSection: 1) == 2)
|
||||
#expect((0..<grid.numberOfSections).reduce(0) { $0 + grid.numberOfItems(inSection: $1) } == EmojiCatalog.all.count)
|
||||
func expectCopied(_ emoji: String) {
|
||||
picker.copySelection()
|
||||
#expect(pasteboard.string(forType: .string) == emoji)
|
||||
}
|
||||
expectCopied("👩💻")
|
||||
picker.moveSelection(by: 1)
|
||||
#expect(picker.handleControlKey("j"))
|
||||
expectCopied("😀")
|
||||
#expect(picker.handleControlKey("k"))
|
||||
expectCopied("🙏")
|
||||
picker.moveSelection(by: -1)
|
||||
#expect(picker.handleControlKey("j"))
|
||||
expectCopied("🚀")
|
||||
#expect(picker.handleControlKey("j"))
|
||||
expectCopied(try #require(EmojiCatalog.all.first { !["👩💻", "🙏", "🚀", "😀"].contains($0.value) }).value)
|
||||
#expect(picker.handleControlKey("k"))
|
||||
expectCopied("🚀")
|
||||
}
|
||||
|
||||
@@ -71,8 +71,13 @@ import Testing
|
||||
func expectVisible() throws {
|
||||
picker.copySelection()
|
||||
let index = try #require(ordered.firstIndex { $0.value == pasteboard.string(forType: .string) })
|
||||
let path = favorites && index >= favored.count
|
||||
? IndexPath(item: index - favored.count, section: 1) : IndexPath(item: index, section: 0)
|
||||
var item = index
|
||||
var section = 0
|
||||
while item >= grid.numberOfItems(inSection: section) {
|
||||
item -= grid.numberOfItems(inSection: section)
|
||||
section += 1
|
||||
}
|
||||
let path = IndexPath(item: item, section: section)
|
||||
let frame = try #require(grid.collectionViewLayout?.layoutAttributesForItem(at: path)?.frame)
|
||||
try #require(scroll.documentVisibleRect.contains(frame))
|
||||
}
|
||||
@@ -239,7 +244,7 @@ import Testing
|
||||
#expect(table.numberOfRows == 1)
|
||||
}
|
||||
|
||||
@Test @MainActor func emojiFavoritesPersistAndNavigationCrossesTheSpacingBreak() throws {
|
||||
@Test @MainActor func emojiFavoritesPersistAndNavigationCrossesSections() throws {
|
||||
_ = NSApplication.shared
|
||||
let suite = "ConjureEmojiFavorites.\(UUID().uuidString)"
|
||||
let defaults = UserDefaults(suiteName: suite)!
|
||||
@@ -254,9 +259,6 @@ import Testing
|
||||
query = ""
|
||||
picker.inputChanged()
|
||||
picker.view.layoutSubtreeIfNeeded()
|
||||
let grid = try #require(picker.view.subviews.compactMap { $0 as? NSScrollView }.first?.documentView as? NSCollectionView)
|
||||
#expect(grid.numberOfSections == 2)
|
||||
#expect(grid.numberOfItems(inSection: 0) == 1)
|
||||
#expect(picker.handleControlKey("j"))
|
||||
picker.copySelection()
|
||||
#expect(pasteboard.string(forType: .string) == EmojiCatalog.all[0].value)
|
||||
@@ -271,7 +273,6 @@ import Testing
|
||||
#expect(picker.handleControlKey("k"))
|
||||
picker.toggleFavorite()
|
||||
#expect(defaults.stringArray(forKey: "favoriteEmoji") == [])
|
||||
#expect(grid.numberOfSections == 1)
|
||||
query = "👩💻"
|
||||
picker.inputChanged()
|
||||
picker.toggleFavorite()
|
||||
|
||||
Reference in New Issue
Block a user