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

+18
Переглянути файл
@@ -1211,6 +1211,24 @@ export function occurrenceNavigator(toolWindow: string): OccurrenceNavigator | n
return occurrenceNavigators.get(toolWindow)?.at(-1) ?? null;
}
// ---------------------------------------------------------------------------
// Edit › Undo / Redo outside text fields and editors
/** Undo / Redo for `focused` in a view with its own history (Project view file operations); true when handled. */
export type UndoHandler = (command: "undo" | "redo", focused: Element) => boolean;
const undoHandlers = new Set<UndoHandler>();
export function registerUndoHandler(handler: UndoHandler): () => void {
undoHandlers.add(handler);
return () => void undoHandlers.delete(handler);
}
/** Offers Undo / Redo to the registered views, latest first. */
export function runUndoHandlers(command: "undo" | "redo", focused: Element): boolean {
return [...undoHandlers].reverse().some((h) => h(command, focused));
}
/** Registers `nav` (the latest render's) for `toolWindow` while the calling view is mounted. */
export function useOccurrenceNavigator(toolWindow: string, nav: OccurrenceNavigator["go"]) {
const latest = useRef(nav);