Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: Skip undo delete toast for empty cells (#5209)

Trevor Manz278316eda002
diff --git a/frontend/src/components/editor/cell/useDeleteCell.tsx b/frontend/src/components/editor/cell/useDeleteCell.tsx
index 53728417af..cc3b43a864 100644
--- a/frontend/src/components/editor/cell/useDeleteCell.tsx
+++ b/frontend/src/components/editor/cell/useDeleteCell.tsx
@@ -1,7 +1,11 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { UndoButton } from "@/components/buttons/undo-button";
import { toast } from "@/components/ui/use-toast";
-import { hasOnlyOneCellAtom, useCellActions } from "@/core/cells/cells";
+import {
+ notebookAtom,
+ hasOnlyOneCellAtom,
+ useCellActions,
+} from "@/core/cells/cells";
import type { CellId } from "@/core/cells/ids";
import { sendDeleteCell } from "@/core/network/requests";
import { store } from "@/core/state/jotai";
@@ -17,25 +21,31 @@ export function useDeleteCellCallback() {
}
const { cellId } = opts;
+ const notebook = store.get(notebookAtom);
+ const isEmptyCell = (notebook.cellData[cellId]?.code ?? "").trim() === "";
+
// Optimistic update
deleteCell({ cellId });
sendDeleteCell({ cellId: cellId }).catch(() => {
// Fall back on failure
undoDeleteCell();
});
- const { dismiss } = toast({
- title: "Cell deleted",
- description:
- "You can bring it back by clicking undo or through the command palette.",
- action: (
- <UndoButton
- data-testid="undo-delete-button"
- onClick={() => {
- undoDeleteCell();
- dismiss();
- }}
- />
- ),
- });
+
+ if (!isEmptyCell) {
+ const { dismiss } = toast({
+ title: "Cell deleted",
+ description:
+ "You can bring it back by clicking undo or through the command palette.",
+ action: (
+ <UndoButton
+ data-testid="undo-delete-button"
+ onClick={() => {
+ undoDeleteCell();
+ dismiss();
+ }}
+ />
+ ),
+ });
+ }
});
}