Skip to content

Commit a4a472e

Browse files
fix(drawer): support keyboard Trash confirmation
1 parent dc036e0 commit a4a472e

6 files changed

Lines changed: 120 additions & 6 deletions

File tree

‎App/FileMint/FileDrawerActions.swift‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,20 @@ extension FileDrawerModel {
229229
guard !items.isEmpty else { return }
230230
let alert = NSAlert()
231231
alert.messageText = text("Move \(items.count) items to Trash?", "将 \(items.count) 项移到废纸篓?")
232-
alert.addButton(withTitle: text("Cancel", "取消"))
233232
alert.addButton(withTitle: text("Move to Trash", "移到废纸篓"))
233+
alert.addButton(withTitle: text("Cancel", "取消")).keyEquivalent = "\u{1b}"
234+
// Require a separate Return press after the action palette opens the sheet.
235+
let repeatMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak sheet = alert.window] event in
236+
guard sheet?.isKeyWindow == true, event.isARepeat,
237+
event.keyCode == 36 || event.keyCode == 76 else { return event }
238+
return nil
239+
}
234240
interacting = true
235241
alert.beginSheetModal(for: window) { [weak self] response in
242+
if let repeatMonitor { NSEvent.removeMonitor(repeatMonitor) }
236243
guard let self else { return }
237244
self.interacting = false
238-
guard self.presented, response == .alertSecondButtonReturn else { return }
245+
guard self.presented, response == .alertFirstButtonReturn else { return }
239246
self.batch(items, work: { try source.folder.trash($0) }, finished: { receipts in
240247
let available = receipts.compactMap { $0 }
241248
if !available.isEmpty { self.trashReceipts.append((available, source.grant)) }

‎docs/ACCEPTANCE.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
Observations below apply to the revisions and environments stated in each entry.
44
Use [HARNESS](../specs/HARNESS.md) to select present-day verification.
55

6+
## Drawer Trash confirmation — 2026-11-30
7+
8+
The signed drawer fixture on arm64 macOS 27.2.1 verified native sheet focus and
9+
the default Move to Trash button from Command-Delete and the action panel. Escape
10+
preserved the selection, and a separate Return reached identity validation with
11+
an isolated fixture. Offline checks and unsigned Release compilation passed on
12+
the worktree based on `dc036e0`. [Verification record](tasks/2026-11-20-file-drawer.md#native-sheet-focus-follow-up).
13+
614
## FileMint 0.9.0 release — 2026-11-30
715

816
The signed build 34 at `2d8e199` became public Latest at 09:43:52 Asia/Shanghai.

‎docs/tasks/2026-11-20-file-drawer.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ Acceptance follows the app, Core and native rows of the [Harness](../../specs/HA
1010

1111
## Drawer refinements
1212

13+
### Trash confirmation keyboard — 2026-11-30
14+
15+
On arm64 macOS 27.2.1 with Xcode 27.2, the worktree based on `dc036e0` passed
16+
`make verify` and unsigned Release compilation for FileMint and its embedded
17+
Finder extension. Logs are in `build/drawer-trash-keyboard.qpZomB/`.
18+
19+
The signed `file-drawer` suite passed in
20+
`build/native-checks.noindex/run.6figt4mi/report.json`. Both keyboard routes
21+
gave the primary Move to Trash button focus. Escape preserved the selection
22+
and file. A held Return kept the sheet open. A fresh Return reached identity
23+
validation and rejected a same-name fixture replacement before system Trash.
24+
25+
The first run `run.z4bmrrth` stopped before Command-Delete because the fixture
26+
had not established file-list focus. `run.zbzs16fz` reached the sheet and failed
27+
the focus assertion. Setting the first responder after attaching the sheet
28+
resolved it in the final run.
29+
30+
#### Native sheet focus follow-up
31+
32+
The follow-up leaves initial control focus to AppKit and uses the native default
33+
button for Return. The signed drawer suite passed in
34+
`build/native-checks.noindex/run.lesllooi/report.json` on the same host. It
35+
opened the sheet from both routes, verified the default button and native
36+
focus, and exercised Escape, repeat suppression and a fresh Return. The first
37+
run `run.iua6w0df` stopped at the folder search focus check before the Trash
38+
scenario. The passing run reused that signed fixture.
39+
40+
The worktree based on `dc036e0` also passed `make verify` and the unsigned Release
41+
build. Logs are in `build/drawer-native-confirmation.9sEEJd/`.
42+
1343
### Drawer keyboard navigation — 2026-11-23
1444

1545
The native folder search field returns focus to the files on Escape and keeps

‎scripts/file_drawer_checks.swift‎

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,12 @@ func checkFileDrawer(settings: PreferencesModel, favorites: FavoriteLocationsMod
279279
controller.toggleFromShortcut()
280280
try await wait("Drawer did not appear") { model.window?.isVisible == true }
281281
guard let window = model.window, let screen = window.screen else { throw failure("No drawer screen") }
282-
func drawerKeyEvent(_ key: String, _ code: UInt16, _ flags: NSEvent.ModifierFlags = [.command]) throws -> NSEvent {
283-
guard let target = model.window,
282+
func drawerKeyEvent(_ key: String, _ code: UInt16, _ flags: NSEvent.ModifierFlags = [.command],
283+
in target: NSWindow? = nil, isARepeat: Bool = false) throws -> NSEvent {
284+
guard let target = target ?? model.window,
284285
let event = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: flags,
285286
timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: target.windowNumber, context: nil,
286-
characters: key, charactersIgnoringModifiers: key, isARepeat: false, keyCode: code) else {
287+
characters: key, charactersIgnoringModifiers: key, isARepeat: isARepeat, keyCode: code) else {
287288
throw failure("Could not create drawer key event: " + key)
288289
}
289290
return event
@@ -703,7 +704,68 @@ func checkFileDrawer(settings: PreferencesModel, favorites: FavoriteLocationsMod
703704
try FileManager.default.removeItem(at: targetFile.url)
704705
try FileManager.default.moveItem(at: retained, to: targetFile.url)
705706
model.refresh()
706-
try await wait("Action fixtures did not refresh") { !model.busy && model.entries.contains { $0.isSameItem(as: targetFile) } }
707+
try await wait("Action fixtures did not refresh") {
708+
!model.busy && !model.isSearching && model.visibleEntries.contains { $0.isSameItem(as: targetFile) }
709+
}
710+
711+
func trashConfirmation() async throws -> NSWindow {
712+
try await wait("Trash confirmation did not become the key sheet") { window.attachedSheet?.isKeyWindow == true }
713+
guard let sheet = window.attachedSheet, let content = sheet.contentView,
714+
let confirm = views(of: NSButton.self, in: content).first(where: {
715+
$0.title == model.text("Move to Trash", "移到废纸篓")
716+
}) else { throw failure("Missing Trash confirmation button") }
717+
try require(confirm.cell === sheet.defaultButtonCell, "Move to Trash was not the default button")
718+
try require(sheet.firstResponder !== confirm, "Move to Trash took control focus when the sheet opened")
719+
return sheet
720+
}
721+
guard let fileList = views(of: NSCollectionView.self, in: container).first else {
722+
throw failure("Missing the file list for Command-Delete")
723+
}
724+
model.selection = [targetFile.url]
725+
window.makeKeyAndOrderFront(nil)
726+
try require(window.makeFirstResponder(fileList), "Could not focus the file list for Command-Delete")
727+
try await wait("The file list did not regain focus for Command-Delete") {
728+
window.isKeyWindow && window.firstResponder === fileList
729+
}
730+
try sendWindowKey("\u{7f}", 51)
731+
let directTrashSheet = try await trashConfirmation()
732+
NSApp.postEvent(try drawerKeyEvent("\u{1b}", 53, [], in: directTrashSheet), atStart: false)
733+
try await wait("Escape did not cancel Trash and return to the selected file") {
734+
window.attachedSheet == nil && !model.interacting && window.isKeyWindow && window.firstResponder === fileList
735+
&& model.selection == [targetFile.url]
736+
}
737+
try require(try Data(contentsOf: targetFile.url) == notes, "Cancelling Trash changed the selected file")
738+
739+
try sendWindowKey("k", 40)
740+
let (trashSearch, _) = try await actionSearch()
741+
filterActions(trashSearch, "移到废纸篓")
742+
try await wait("Trash did not match the action search") {
743+
axElement("drawer.action.trash") != nil && axElement("drawer.action.copyPaths") == nil
744+
}
745+
window.sendEvent(try drawerKeyEvent("\r", 36, []))
746+
let paletteTrashSheet = try await trashConfirmation()
747+
try require(model.actionPalette == nil && (try Data(contentsOf: targetFile.url)) == notes,
748+
"Running the palette action skipped the Trash confirmation")
749+
// Replace the captured file after opening the sheet so the real write rejects it before calling system Trash.
750+
let replacement = Data("replacement before Trash confirmation".utf8)
751+
try FileManager.default.moveItem(at: targetFile.url, to: retained)
752+
try replacement.write(to: targetFile.url, options: .withoutOverwriting)
753+
NSApp.postEvent(try drawerKeyEvent("\r", 36, [], in: paletteTrashSheet, isARepeat: true), atStart: false)
754+
try await Task.sleep(for: .milliseconds(120))
755+
try require(window.attachedSheet === paletteTrashSheet && model.interacting, "A repeated Return confirmed Trash")
756+
NSApp.postEvent(try drawerKeyEvent("\r", 36, [], in: paletteTrashSheet), atStart: false)
757+
let rejectedTrash = model.text("Completed 0/1. ", "已完成 0/1 项。") + model.errorText(FileMoveError.sourceChanged)
758+
try await wait("Return did not confirm Trash through the existing identity check") {
759+
window.attachedSheet == nil && !model.interacting && !model.busy && model.message == rejectedTrash
760+
}
761+
try require(try Data(contentsOf: targetFile.url) == replacement && Data(contentsOf: retained) == notes,
762+
"Confirming Trash changed the replacement or the original")
763+
try FileManager.default.removeItem(at: targetFile.url)
764+
try FileManager.default.moveItem(at: retained, to: targetFile.url)
765+
model.refresh()
766+
try await wait("Trash fixture did not refresh") { !model.busy && model.entries.contains { $0.isSameItem(as: targetFile) } }
767+
print("PASS drawer Trash keyboard: native sheet focus from both routes, Escape, fresh Return and stale-file protection")
768+
fflush(nil)
707769

708770
// Exercise the picker with the QA bundle itself as an explicitly configured app.
709771
// Native document delivery is checked separately with the signed Open With receiver.

‎specs/domains/file-drawer.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ While the drawer owns keyboard focus, Command-K opens or closes actions for its
6969

7070
In the action panel, Return runs the highlighted row. Other visible key hints invoke their corresponding actions directly. Preserve native text editing in the action search, including copy, paste and composing text.
7171

72+
Command-Delete in the file list and Move to Trash in the action panel open the same native confirmation sheet. Leave initial control focus to AppKit. A fresh Return activates the primary Move to Trash button, and Escape cancels while preserving the selection.
73+
7274
The drawer handles Command-W to close, Command-Shift-P to pin, Command-N to create a file and Command-Shift-N to create a folder while it is the key window, including when folder search has focus. Command-1 through 9 open the first nine standard places in sidebar order. In the file list, Command-Option-1, 2 and 3 switch to icons, list and compact list. Use plain Left to go to the parent, plain Right to enter a selected folder and Command-O to open a selection. Name editing, IME composition, menus, sheets and drafts retain priority. File selection, rename, preview, copy/move, copy paths, reveal, favorites, Trash and restoration remain local to the file list.
7375

7476
Command-F focuses folder search. Return from search selects a result and moves focus to the file list. While folder search owns focus, Escape returns focus to the file list and preserves the query and filtered results, including when the field is empty. Escape in the file list closes an open preview first, or closes the drawer when there is no preview.

‎specs/verification/native-qa.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ same-name replacement. Its multi-file move keeps a source filter and selection
9292
on Escape, rejects a collision before moving either file, and retries against the
9393
captured child folder. The Open With page covers the app list, filtering, Other
9494
Application, cancellation and stale rows.
95+
The Trash confirmation check opens the sheet from Command-Delete and from the
96+
action panel. It checks native sheet focus, the primary default button, Escape
97+
cancellation, key repeat and a fresh Return. It replaces the captured fixture
98+
before confirming. Identity validation rejects the write before the system
99+
Trash call.
95100
The signed `open-with` suite checks delivery of file and folder URLs to a receiver.
96101
The drawer fixture creates a file from
97102
an unpinned drawer, edits a filename in place, checks collision and stale-identity

0 commit comments

Comments
 (0)