feat: make new-file reject undo persistent
Allow Ctrl/Cmd+Z to restore previously rejected NEW files without a time limit, while keeping normal editor undo behavior intact. Made-with: Cursor
This commit is contained in:
parent
7fbf240c70
commit
caa2cae575
2 changed files with 13 additions and 9 deletions
|
|
@ -606,14 +606,18 @@ export const ChangeReviewDialog = ({
|
||||||
// even if focus is inside a CM editor (focus often remains there after clicking buttons).
|
// even if focus is inside a CM editor (focus often remains there after clicking buttons).
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
// Undo: recently rejected NEW file (deleted from disk + removed from review list)
|
// Undo: rejected NEW file (deleted from disk + removed from review list)
|
||||||
const removedRecently = now - lastNewFileRemoveAtRef.current < 30_000;
|
|
||||||
const removedStack = removedNewFileUndoStackRef.current;
|
const removedStack = removedNewFileUndoStackRef.current;
|
||||||
if (
|
const lastHunkAt = Object.values(lastHunkActionAtRef.current).reduce(
|
||||||
removedRecently &&
|
(max, v) => Math.max(max, v),
|
||||||
removedStack.length > 0 &&
|
0
|
||||||
!document.activeElement?.closest('.cm-editor')
|
);
|
||||||
) {
|
const lastReviewActionAt = Math.max(lastBulkActionAtRef.current, lastHunkAt);
|
||||||
|
const newFileWasLastAction = lastNewFileRemoveAtRef.current >= lastReviewActionAt;
|
||||||
|
const isInEditor = !!document.activeElement?.closest('.cm-editor');
|
||||||
|
const lastViewConnected = !!lastFocusedEditorRef.current?.dom.isConnected;
|
||||||
|
const shouldPreferEditorUndo = isInEditor && lastViewConnected;
|
||||||
|
if (newFileWasLastAction && removedStack.length > 0 && !shouldPreferEditorUndo) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const snap = removedStack.pop()!;
|
const snap = removedStack.pop()!;
|
||||||
|
|
@ -621,7 +625,7 @@ export const ChangeReviewDialog = ({
|
||||||
...snap.file,
|
...snap.file,
|
||||||
originalFullContent: '',
|
originalFullContent: '',
|
||||||
modifiedFullContent: snap.restoreContent,
|
modifiedFullContent: snap.restoreContent,
|
||||||
contentSource: 'disk-current',
|
contentSource: 'snippet-reconstruction',
|
||||||
};
|
};
|
||||||
addReviewFile(snap.file, { index: snap.index, content: restoredContent });
|
addReviewFile(snap.file, { index: snap.index, content: restoredContent });
|
||||||
setActiveFilePath(snap.file.filePath);
|
setActiveFilePath(snap.file.filePath);
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ export const ReviewToolbar = ({
|
||||||
Undo
|
Undo
|
||||||
</button>
|
</button>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent side="bottom">Undo last bulk operation (Ctrl+Z)</TooltipContent>
|
<TooltipContent side="bottom">Undo last review operation (Ctrl+Z)</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue