feat(project-tree): Undo restores files deleted in the Project view (#1103)

Ctrl+Z / Cmd+Z in the Project view (and Edit › Undo while it has focus) reverts the latest file operation there: a delete as well as a move or rename. Deleted files come back from their last Local History snapshot, folders are re-created and the restored items selected; items without a snapshot are named in a warning. Edit › Undo reaches the view through a new registerUndoHandler contribution; the Project view is found by a data attribute instead of its translated aria-label (also fixes the New popup's fallback anchor).
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-04 04:53:48 +08:00
1 джерело fe0ee338f4
коміт 5ad5dc2a28
8 files changed
+184 -11

No files matched your search

+4 -4
Переглянути файл
@@ -60,7 +60,6 @@ import { relativePath } from "@/platform/project";
import { folderKind } from "./folderKind";
import { useHomeDir } from "./home";
import { keyLike, memberNodes, nodeKeyFor, visibleInfo, type ProjectNode } from "./model";
import { lastFileRefactoring, undoFileRefactoring } from "./fileRefactor";
import {
cancelEditing,
checkEditingName,
@@ -77,6 +76,7 @@ import {
paste,
refreshOsClipboard,
targetFolder,
undoLastFileOperation,
} from "./operations";
import { isInside, nameOf, parentOf, splitExtension, tildify } from "./paths";
import {
@@ -111,7 +111,7 @@ export function showNewPopup(): boolean {
const lead = treeHandle.current?.leadKey();
const row = lead ? document.querySelector<HTMLElement>(`[data-project-key="${CSS.escape(lead)}"]`) : null;
const rect = (
row ?? document.querySelector<HTMLElement>('[role="tree"][aria-label="Project"]')
row ?? document.querySelector<HTMLElement>('[data-project-view] [role="tree"]')
)?.getBoundingClientRect();
if (!rect) return false;
openNewPopup({ x: rect.left + 24, y: rect.bottom }, newMenuItems(targetFolder()));
@@ -705,8 +705,7 @@ export function ProjectView() {
openMoveDialog();
break;
case "Meta+Z":
if (lastFileRefactoring()) void undoFileRefactoring();
else handled = false;
handled = undoLastFileOperation();
break;
case "Meta+C":
copySelection(false);
@@ -767,6 +766,7 @@ export function ProjectView() {
<div
ref={containerRef}
className={styles.view}
data-project-view=""
{...OWNS_FILE_DROP}
onKeyDown={onKeyDown}
// The native Edit menu may take ⌘C/⌘X/⌘V before the keymap sees them; it then sends DOM clipboard events.