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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
address review comments from #8019 (#9549)
Shahmir Varqha16df3e6e4787
diff --git a/frontend/src/components/editor/navigation/__tests__/clipboard.test.ts b/frontend/src/components/editor/navigation/__tests__/clipboard.test.tsindex 7bcba3c114..5f9ff34833 100644--- a/frontend/src/components/editor/navigation/__tests__/clipboard.test.ts+++ b/frontend/src/components/editor/navigation/__tests__/clipboard.test.ts@@ -28,7 +28,6 @@ vi.mock("@/core/cells/pending-cut-service", () => ({}),usePendingCutState: () => ({cellIds: new Set(),- clipboardData: null,}),}));diff --git a/frontend/src/components/editor/navigation/clipboard.ts b/frontend/src/components/editor/navigation/clipboard.tsindex f49e65903d..f421c55c0e 100644--- a/frontend/src/components/editor/navigation/clipboard.ts+++ b/frontend/src/components/editor/navigation/clipboard.ts@@ -42,9 +42,19 @@ const ClipboardCellDataSchema = z.object({version: z.literal("1.0"),});-function buildClipboardPayload(- cells: Array<{ code: string; name?: string; config?: CellConfig }>,-): { clipboardData: ClipboardCellData; plainText: string } {+interface ClipboardCellInput {+ code: string;+ name?: string;+ config?: CellConfig;+}++function toPlainText(cells: ClipboardCellInput[]): string {+ return cells.map((cell) => cell.code).join("\n\n");+}++async function writeCellsToClipboard(+ cells: ClipboardCellInput[],+): Promise<void> {const clipboardData: ClipboardCellData = {cells: cells.map((cell) => ({code: cell.code,@@ -53,17 +63,9 @@ function buildClipboardPayload(})),version: "1.0",};- const plainText = cells.map((cell) => cell.code).join("\n\n");- return { clipboardData, plainText };-}--async function writeCellsToClipboard(- clipboardData: ClipboardCellData,- plainText: string,-): Promise<void> {const clipboardItem = new ClipboardItemBuilder().add(MARIMO_CELL_MIMETYPE, clipboardData)- .add("text/plain", plainText)+ .add("text/plain", toPlainText(cells)).build();await navigator.clipboard.write([clipboardItem]);}@@ -80,14 +82,11 @@ export function useCellClipboard() {.filter(Boolean);if (cells.length === 0) {- // No cells to copyreturn;}- const { clipboardData, plainText } = buildClipboardPayload(cells);-try {- await writeCellsToClipboard(clipboardData, plainText);+ await writeCellsToClipboard(cells);pendingCutActions.clear();toastSuccess(cells.length);} catch (error) {@@ -95,7 +94,7 @@ export function useCellClipboard() {// Fallback to simple text copytry {- await copyToClipboard(plainText);+ await copyToClipboard(toPlainText(cells));pendingCutActions.clear();toastSuccess(cells.length);} catch {@@ -110,21 +109,18 @@ export function useCellClipboard() {const cells = validCellIds.map((cellId) => notebook.cellData[cellId]);if (cells.length === 0) {- // No cells to cutreturn;}- const { clipboardData, plainText } = buildClipboardPayload(cells);-try {- await writeCellsToClipboard(clipboardData, plainText);- pendingCutActions.markForCut({ cellIds: validCellIds, clipboardData });+ await writeCellsToClipboard(cells);+ pendingCutActions.markForCut({ cellIds: validCellIds });} catch (error) {Logger.error("Failed to cut cells to clipboard", error);try {- await copyToClipboard(plainText);+ await copyToClipboard(toPlainText(cells));// Mark cells as pending cut instead of deleting immediately- pendingCutActions.markForCut({ cellIds: validCellIds, clipboardData });+ pendingCutActions.markForCut({ cellIds: validCellIds });} catch {toastError();}diff --git a/frontend/src/core/cells/__tests__/cells.test.ts b/frontend/src/core/cells/__tests__/cells.test.tsindex 0be339aa95..768935812f 100644--- a/frontend/src/core/cells/__tests__/cells.test.ts+++ b/frontend/src/core/cells/__tests__/cells.test.ts@@ -622,7 +622,7 @@ describe("cell reducer", () => {before: false,});actions.createNewCell({- cellId: "1" as CellId,+ cellId: cellId("1"),before: false,});expect(formatCells(state)).toMatchInlineSnapshot(`@@ -637,8 +637,8 @@ describe("cell reducer", () => {// Move first two cells after the thirdactions.moveCellsRelativeTo({- cellIds: [firstCellId, "1" as CellId],- targetCellId: "2" as CellId,+ cellIds: [firstCellId, cellId("1")],+ targetCellId: cellId("2"),position: "after",});expect(formatCells(state)).toMatchInlineSnapshot(`@@ -658,7 +658,7 @@ describe("cell reducer", () => {before: false,});actions.createNewCell({- cellId: "1" as CellId,+ cellId: cellId("1"),before: false,});expect(formatCells(state)).toMatchInlineSnapshot(`@@ -682,14 +682,14 @@ describe("cell reducer", () => {{columnId: col.id,index: col.indexOfOrThrow(- "1" as CellId,+ cellId("1"),) as import("@/utils/id-tree").CellIndex,},];actions.moveCellsRelativeTo({- cellIds: [firstCellId, "1" as CellId],- targetCellId: "2" as CellId,+ cellIds: [firstCellId, cellId("1")],+ targetCellId: cellId("2"),position: "after",previousPlacements,});@@ -721,7 +721,7 @@ describe("cell reducer", () => {before: false,});actions.createNewCell({- cellId: "1" as CellId,+ cellId: cellId("1"),before: false,});@@ -736,14 +736,14 @@ describe("cell reducer", () => {{columnId: col.id,index: col.indexOfOrThrow(- "1" as CellId,+ cellId("1"),) as import("@/utils/id-tree").CellIndex,},];actions.moveCellsRelativeTo({- cellIds: [firstCellId, "1" as CellId],- targetCellId: "2" as CellId,+ cellIds: [firstCellId, cellId("1")],+ targetCellId: cellId("2"),position: "after",previousPlacements,});@@ -757,7 +757,7 @@ describe("cell reducer", () => {"`);- actions.deleteCell({ cellId: "2" as CellId });+ actions.deleteCell({ cellId: cellId("2") });expect(formatCells(state)).toMatchInlineSnapshot(`"[0] ''diff --git a/frontend/src/core/cells/__tests__/pending-cut-service.test.tsx b/frontend/src/core/cells/__tests__/pending-cut-service.test.tsxindex 1d29398990..54197fd1a3 100644--- a/frontend/src/core/cells/__tests__/pending-cut-service.test.tsx+++ b/frontend/src/core/cells/__tests__/pending-cut-service.test.tsx@@ -3,6 +3,7 @@import { act, renderHook } from "@testing-library/react";import { createStore, Provider } from "jotai";import { describe, expect, it } from "vitest";+import { cellId } from "@/__tests__/branded";import type { CellId } from "@/core/cells/ids";import {pendingCutStateAtom,@@ -20,15 +21,10 @@ function createTestWrapper() {return { wrapper, store };}-const mockClipboardData = {- cells: [{ code: "x = 1", name: "cell1" }],- version: "1.0" as const,-};-describe("pending-cut-service", () => {- it("markForCut sets cellIds and clipboardData", () => {+ it("markForCut sets cellIds", () => {const { wrapper, store } = createTestWrapper();- const cellIds: CellId[] = ["cell-1" as CellId, "cell-2" as CellId];+ const cellIds: CellId[] = [cellId("cell-1"), cellId("cell-2")];const { result } = renderHook(() => ({@@ -39,20 +35,16 @@ describe("pending-cut-service", () => {);act(() => {- result.current.actions.markForCut({- cellIds,- clipboardData: mockClipboardData,- });+ result.current.actions.markForCut({ cellIds });});const state = store.get(pendingCutStateAtom);expect(state.cellIds).toEqual(new Set(cellIds));- expect(state.clipboardData).toEqual(mockClipboardData);});it("clear resets to initial state", () => {const { wrapper, store } = createTestWrapper();- const cellIds: CellId[] = ["cell-1" as CellId];+ const cellIds: CellId[] = [cellId("cell-1")];const { result } = renderHook(() => ({@@ -63,10 +55,7 @@ describe("pending-cut-service", () => {);act(() => {- result.current.actions.markForCut({- cellIds,- clipboardData: mockClipboardData,- });+ result.current.actions.markForCut({ cellIds });});expect(store.get(pendingCutStateAtom).cellIds.size).toBe(1);@@ -75,28 +64,24 @@ describe("pending-cut-service", () => {});const state = store.get(pendingCutStateAtom);expect(state.cellIds.size).toBe(0);- expect(state.clipboardData).toBeNull();});it("useIsPendingCut returns true when cellId is marked for cut", () => {const { wrapper } = createTestWrapper();- const cellId = "cell-1" as CellId;+ const targetCellId = cellId("cell-1");const { result: actionsResult } = renderHook(() => usePendingCutActions(), {wrapper,});const { result: isPendingResult } = renderHook(- () => useIsPendingCut(cellId),+ () => useIsPendingCut(targetCellId),{ wrapper },);expect(isPendingResult.current).toBe(false);act(() => {- actionsResult.current.markForCut({- cellIds: [cellId],- clipboardData: mockClipboardData,- });+ actionsResult.current.markForCut({ cellIds: [targetCellId] });});expect(isPendingResult.current).toBe(true);@@ -104,19 +89,15 @@ describe("pending-cut-service", () => {it("useIsPendingCut returns false when cellId is not marked for cut", () => {const { wrapper } = createTestWrapper();- const { result } = renderHook(- () => useIsPendingCut("other-cell" as CellId),- { wrapper },- );+ const { result } = renderHook(() => useIsPendingCut(cellId("other-cell")), {+ wrapper,+ });const { result: actionsResult } = renderHook(() => usePendingCutActions(), {wrapper,});act(() => {- actionsResult.current.markForCut({- cellIds: ["cell-1" as CellId],- clipboardData: mockClipboardData,- });+ actionsResult.current.markForCut({ cellIds: [cellId("cell-1")] });});expect(result.current).toBe(false);@@ -134,10 +115,7 @@ describe("pending-cut-service", () => {expect(hasPendingResult.current).toBe(false);act(() => {- actionsResult.current.markForCut({- cellIds: ["cell-1" as CellId],- clipboardData: mockClipboardData,- });+ actionsResult.current.markForCut({ cellIds: [cellId("cell-1")] });});expect(hasPendingResult.current).toBe(true);diff --git a/frontend/src/core/cells/pending-cut-service.ts b/frontend/src/core/cells/pending-cut-service.tsindex 90d25209c5..d0f3c64db9 100644--- a/frontend/src/core/cells/pending-cut-service.ts+++ b/frontend/src/core/cells/pending-cut-service.ts@@ -1,31 +1,24 @@/* Copyright 2026 Marimo. All rights reserved. */import { atom, useAtomValue } from "jotai";-import type { ClipboardCellData } from "@/components/editor/navigation/clipboard";import type { CellId } from "@/core/cells/ids";import { createReducerAndAtoms } from "@/utils/createReducer";interface PendingCutState {cellIds: Set<CellId>;- clipboardData: ClipboardCellData | null;}const initialState = (): PendingCutState => ({cellIds: new Set(),- clipboardData: null,});const {valueAtom: pendingCutStateAtom,useActions: usePendingCutActionsInternal,} = createReducerAndAtoms(initialState, {- markForCut: (- _state,- action: { cellIds: CellId[]; clipboardData: ClipboardCellData },- ) => {+ markForCut: (_state, action: { cellIds: CellId[] }) => {return {cellIds: new Set(action.cellIds),- clipboardData: action.clipboardData,};},clear: () => {@@ -33,10 +26,8 @@ const {},});-// Re-export the state atomexport { pendingCutStateAtom };-// Derived atom just for cell IDs (for easier consumption)export const pendingCutCellIdsAtom = atom((get) => get(pendingCutStateAtom).cellIds,);diff --git a/frontend/src/css/app/Cell.css b/frontend/src/css/app/Cell.cssindex e5bd80ab5d..cce5e903fa 100644--- a/frontend/src/css/app/Cell.css+++ b/frontend/src/css/app/Cell.css@@ -75,14 +75,11 @@/* Styling for cells marked for cut */&.pending-cut {- opacity: 0.6;- border-style: dashed;- border-color: var(--amber-7);-.output-area,.cm-gutters,.cm {- background-color: var(--amber-2);+ background-color: var(--gray-2);+ opacity: 0.55;}}