fix: make Backspace delete the selection in Files, as in Mail, and keep Alt+Up for going up

This commit is contained in:
Linus Rath
2026-10-28 03:22:37 +01:00
parent 02ce389140
commit 91f9213110
2 changed files with 25 additions and 2 deletions
@@ -354,4 +354,26 @@ describe('FileBrowser', () => {
fireEvent.keyDown(input, { key: 'Escape' });
expect(screen.queryByRole('dialog', { name: 'rename_title' })).toBeNull();
});
it("deletes the selection with Backspace, as Mail does, and goes up a folder only with Alt+Up", () => {
const onDelete = vi.fn(async () => {});
const onNavigate = vi.fn();
renderBrowser({ props: { currentPath: '/Documents', selectedResources: new Set(['notes.txt']), onDelete, onNavigate } });
fireEvent.keyDown(window, { key: 'Backspace' });
expect(onDelete).toHaveBeenCalledWith('notes.txt');
expect(onNavigate).not.toHaveBeenCalled();
fireEvent.keyDown(window, { key: 'ArrowUp', altKey: true });
expect(onNavigate).toHaveBeenCalled();
});
it("keeps the selection when Escape closes an item's menu", () => {
const onClearSelection = vi.fn();
renderBrowser({ props: { selectedResources: new Set(['notes.txt', 'Documents']), onClearSelection } });
fireEvent.contextMenu(within(list()).getByText('notes.txt'));
expect(screen.getByRole('menu')).toBeInTheDocument();
fireEvent.keyDown(document.activeElement ?? window, { key: 'Escape' });
expect(screen.queryByRole('menu')).toBeNull();
expect(onClearSelection).not.toHaveBeenCalled();
});
});
+3 -2
View File
@@ -704,7 +704,8 @@ export function FileBrowser({
else if (selected.length > 0) onClearSelection();
return;
}
if (e.key === "Delete" && selected.length > 0) {
// Backspace deletes too, as in Mail (⌘⌫ on a Mac); Alt+↑ goes up.
if ((e.key === "Delete" || e.key === "Backspace") && selected.length > 0) {
e.preventDefault();
deleteNames(selected);
return;
@@ -724,7 +725,7 @@ export function FileBrowser({
onToggleSelect(focusedName);
return;
}
if ((e.key === "Backspace" || (e.altKey && e.key === "ArrowUp")) && currentPath !== "/") {
if (e.altKey && e.key === "ArrowUp" && currentPath !== "/") {
e.preventDefault();
navigateUp();
return;