style: use shared notes browsing and actions panels

This commit is contained in:
Valdemar Lorenzen
2026-10-19 10:51:45 +02:00
parent 0b5d27752c
commit 9ce2997c19
8 changed files with 487 additions and 128 deletions
@@ -118,4 +118,91 @@ struct LanguagePickerTests {
}
}
}
@Test @MainActor
func notesShareScrollableFuzzySelectionAndKeepDuplicateTitlesDistinct() throws {
_ = NSApplication.shared
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 750, height: 474),
styleMask: .borderless, backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
let host = try #require(window.contentView)
let pill = NSView(frame: NSRect(x: 500, y: 8, width: 230, height: 36))
let anchor = NSButton(frame: pill.bounds)
pill.addSubview(anchor)
host.addSubview(pill)
let popup = ApplicationActionsController()
defer { popup.close(animated: false); window.orderOut(nil) }
var notes = (0..<20).map { (id: UUID(), title: String(format: "Note %02d", $0)) }
notes[18].title = "Shared Plan"
notes[19].title = "Shared Plan"
var selected: UUID?
popup.selectNote = { selected = $0 }
popup.showNotes(notes, selected: notes[19].id, relativeTo: anchor)
host.layoutSubtreeIfNeeded()
let table = try #require(descendants(popup.view).compactMap { $0 as? NSTableView }.first)
#expect(table.accessibilityLabel() == "Notes")
#expect(table.numberOfRows == 20)
#expect(table.selectedRow == 19)
#expect(NSLocationInRange(table.selectedRow, table.rows(in: table.visibleRect)))
#expect(table.visibleRect.height < table.bounds.height)
let currentCell = try #require(table.view(atColumn: 0, row: 19, makeIfNecessary: true))
let current = try #require(descendants(currentCell).compactMap { $0 as? NSButton }.first)
#expect(current.accessibilityValue() as? String == "Current note")
popup.moveSelection(by: -1)
#expect(popup.handle(#selector(NSResponder.insertNewline(_:))))
#expect(selected == notes[18].id)
popup.close(animated: false)
popup.showNotes(notes, selected: notes[19].id, relativeTo: anchor)
let search = try #require(descendants(popup.view).compactMap { $0 as? NSSearchField }.first)
#expect(search.accessibilityLabel() == "Search notes")
search.stringValue = "shpl"
search.delegate?.controlTextDidChange?(Notification(name: NSControl.textDidChangeNotification, object: search))
let filteredTable = try #require(descendants(popup.view).compactMap { $0 as? NSTableView }.first)
#expect(filteredTable.numberOfRows == 2)
popup.moveSelection(by: 1)
#expect(popup.handle(#selector(NSResponder.insertNewline(_:))))
#expect(selected == notes[19].id)
}
@Test @MainActor
func notesActionsSearchAndCommandShortcutsUseTheSharedPopup() throws {
_ = NSApplication.shared
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 750, height: 474),
styleMask: .borderless, backing: .buffered, defer: false)
window.isReleasedWhenClosed = false
let host = try #require(window.contentView)
let pill = NSView(frame: NSRect(x: 500, y: 8, width: 230, height: 36))
let anchor = NSButton(frame: pill.bounds)
pill.addSubview(anchor)
host.addSubview(pill)
let popup = ApplicationActionsController()
defer { popup.close(animated: false); window.orderOut(nil) }
var browsed = 0
var created = 0
popup.browseNotes = { browsed += 1 }
popup.newNote = { created += 1 }
popup.showNotesActions(relativeTo: anchor)
let search = try #require(descendants(popup.view).compactMap { $0 as? NSSearchField }.first)
#expect(search.accessibilityLabel() == "Search notes actions")
search.stringValue = "new"
search.delegate?.controlTextDidChange?(Notification(name: NSControl.textDidChangeNotification, object: search))
#expect(popup.handle(#selector(NSResponder.insertNewline(_:))))
#expect(created == 1)
popup.close(animated: false)
for key in ["p", "n"] {
popup.showNotesActions(relativeTo: anchor)
let field = try #require(descendants(popup.view).compactMap { $0 as? NSSearchField }.first)
let event = try #require(NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: .command,
timestamp: 0, windowNumber: window.windowNumber, context: nil, characters: key,
charactersIgnoringModifiers: key, isARepeat: false, keyCode: key == "p" ? 35 : 45))
#expect(field.performKeyEquivalent(with: event))
#expect(!popup.isShown)
popup.close(animated: false)
}
#expect(browsed == 1)
#expect(created == 2)
}
}