feat(explorer): wire DEL and Shift+DEL keybinds for file deletion

Register explorer.delete (DEL / Cmd+Backspace) and
explorer.permanentDelete (Shift+DEL / Cmd+Alt+Backspace) handlers in
useExplorerKeyboard, using the same confirm + mutateAsync pattern as
the context menu. Clears selection after successful delete.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
slvnlrt
2026-03-18 21:57:36 +01:00
parent 489fe31c7d
commit 1b18f11f7d

View File

@@ -8,6 +8,7 @@ import { useKeybind } from "../../../hooks/useKeybind";
import { useKeybindScope } from "../../../hooks/useKeybindScope";
import { useClipboard } from "../../../hooks/useClipboard";
import { useFileOperationDialog } from "../../../components/modals/FileOperationModal";
import { useLibraryMutation } from "../../../contexts/SpacedriveContext";
import { isInputFocused } from "../../../util/keybinds/platform";
export function useExplorerKeyboard() {
@@ -36,6 +37,7 @@ export function useExplorerKeyboard() {
} = useSelection();
const clipboard = useClipboard();
const openFileOperation = useFileOperationDialog();
const deleteFiles = useLibraryMutation("files.delete");
// Activate explorer keybind scope when this hook is active
useKeybindScope("explorer");
@@ -160,6 +162,66 @@ export function useExplorerKeyboard() {
{ enabled: selectedFiles.length === 1 },
);
// Delete: Move to trash
useKeybind(
"explorer.delete",
async () => {
if (selectedFiles.length === 0) return;
const hasVirtual = selectedFiles.some((f) => !f.sd_path);
if (hasVirtual) return;
const message =
selectedFiles.length > 1
? `Delete ${selectedFiles.length} items?`
: `Delete "${selectedFiles[0].name}"?`;
if (confirm(message)) {
try {
await deleteFiles.mutateAsync({
targets: { paths: selectedFiles.map((f) => f.sd_path) },
permanent: false,
recursive: true,
});
clearSelection();
} catch (err) {
console.error("Failed to delete:", err);
alert(`Failed to delete: ${err}`);
}
}
},
{ enabled: selectedFiles.length > 0 },
);
// Permanent Delete: Shift+Delete / Cmd+Alt+Backspace
useKeybind(
"explorer.permanentDelete",
async () => {
if (selectedFiles.length === 0) return;
const hasVirtual = selectedFiles.some((f) => !f.sd_path);
if (hasVirtual) return;
const message =
selectedFiles.length > 1
? `Permanently delete ${selectedFiles.length} items? This cannot be undone.`
: `Permanently delete "${selectedFiles[0].name}"? This cannot be undone.`;
if (confirm(message)) {
try {
await deleteFiles.mutateAsync({
targets: { paths: selectedFiles.map((f) => f.sd_path) },
permanent: true,
recursive: true,
});
clearSelection();
} catch (err) {
console.error("Failed to delete:", err);
alert(`Failed to delete: ${err}`);
}
}
},
{ enabled: selectedFiles.length > 0 },
);
useEffect(() => {
const handleKeyDown = async (e: KeyboardEvent) => {
// Skip all keyboard shortcuts if renaming or typing in an input