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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
XCircleIcon,
ChevronLeftIcon,
ChevronRightIcon,
ScissorsIcon,
} from "lucide-react";
import type { ActionButton } from "./types";
import { MultiIcon } from "@/components/icons/multi-icon";
Expand Down Expand Up @@ -54,6 +55,7 @@ import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";
import type { CellConfig, RuntimeState } from "@/core/network/types";
import { kioskModeAtom } from "@/core/mode";
import { switchLanguage } from "@/core/codemirror/language/extension";
import { useSplitCellCallback } from "../cell/useSplitCell";

export interface CellActionButtonProps
extends Pick<CellData, "name" | "config"> {
Expand All @@ -79,6 +81,7 @@ export function useCellActionButtons({ cell }: Props) {
addColumnBreakpoint,
clearCellOutput,
} = useCellActions();
const splitCell = useSplitCellCallback();
const runCell = useRunCell(cell?.cellId);
const hasOnlyOneCell = useAtomValue(hasOnlyOneCellAtom);
const canDelete = !hasOnlyOneCell;
Expand Down Expand Up @@ -185,6 +188,12 @@ export function useCellActionButtons({ cell }: Props) {
},
hotkey: "cell.aiCompletion",
},
{
icon: <ScissorsIcon size={13} strokeWidth={1.5} />,
label: "Split cell",
hotkey: "cell.splitCell",
handle: () => splitCell({ cellId }),
},
{
icon: <ImageIcon size={13} strokeWidth={1.5} />,
label: "Export output as PNG",
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/editor/cell/useSplitCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UndoButton } from "@/components/buttons/undo-button";
import { toast } from "@/components/ui/use-toast";
import { getCellEditorView, useCellActions } from "@/core/cells/cells";
import type { CellId } from "@/core/cells/ids";
import { getEditorCodeAsPython } from "@/core/codemirror/language/utils";
import useEvent from "react-use-event-hook";

export function useSplitCellCallback() {
Expand All @@ -11,7 +12,10 @@ export function useSplitCellCallback() {
return useEvent((opts: { cellId: CellId }) => {
// Save snapshot of code for undo
const cellEditorView = getCellEditorView(opts.cellId);
const code = cellEditorView?.state.doc.toString() ?? "";
if (!cellEditorView) {
return;
}
const code = getEditorCodeAsPython(cellEditorView);

// Optimistic update
splitCell(opts);
Expand Down
Loading