Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/renderer/components/FileTree/FileTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,26 @@ function FileTreeNode({
return () => window.removeEventListener("clipboard-updated", handleClipboardUpdate);
}, [node.path]);

// Fix: If the cut file is saved by the user, cancel the cut state.
useEffect(() => {
if (node.type !== "file") return;
const handleFileSaved = (e: Event) => {
const savedPath = (e as CustomEvent<{ path: string }>).detail?.path;
const normalizedSaved = savedPath?.replace(/\\/g, "/");
const normalizedNode = node.path.replace(/\\/g, "/");
if (
fileClipboard?.action === "cut" &&
fileClipboard?.path.replace(/\\/g, "/") === normalizedNode &&
normalizedSaved === normalizedNode
) {
fileClipboard = null;
window.dispatchEvent(new CustomEvent("clipboard-updated"));
}
};
window.addEventListener("file-manually-saved", handleFileSaved);
return () => window.removeEventListener("file-manually-saved", handleFileSaved);
}, [node.path, node.type]);

useEffect(() => {
if (expanded && typeof refreshTrigger === 'number' && refreshTrigger > 0) {
loadChildren();
Expand Down Expand Up @@ -515,7 +535,12 @@ function FileTreeNode({
const fileName = fileClipboard.path.substring(Math.max(fileClipboard.path.lastIndexOf("/"), fileClipboard.path.lastIndexOf("\\")) + 1);
const newPath = `${targetDir}/${fileName}`.replace(/\\/g, "/");

if (fileClipboard.action === "cut" && newPath === fileClipboard.path) return;
if (fileClipboard.action === "cut" && newPath === fileClipboard.path) {
// Pasting in the same location: just cancel the cut instead of moving.
fileClipboard = null;
window.dispatchEvent(new CustomEvent("clipboard-updated"));
return;
}

try {
if (fileClipboard.action === "cut") {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/pages/IDE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,8 @@ function IDEContent() {
: t,
),
);
// Always notify the file tree so it can cancel any cut state on this path.
window.dispatchEvent(new CustomEvent("file-manually-saved", { detail: { path: activeTab.path } }));
if (hotReload) {
window.dispatchEvent(new CustomEvent("file-saved"));
}
Expand Down
Loading