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
Add actions for expanding/collapsing all outputs (#11045)
Martha Cryane0b2b4d9e42e
diff --git a/frontend/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts b/frontend/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.tsnew file mode 100644index 0000000000..9dd1890d1a--- /dev/null+++ b/frontend/src/components/editor/actions/__tests__/useSetOutputsExpanded.test.ts@@ -0,0 +1,42 @@+/* Copyright 2026 Marimo. All rights reserved. */++import { describe, expect, it } from "vitest";+import { MockNotebook } from "@/__mocks__/notebook";+import type { OutputMessage } from "@/core/kernel/messages";+import { outputExpansionConfigs } from "../useSetOutputsExpanded";++const output: OutputMessage = {+ channel: "output",+ mimetype: "text/plain",+ data: "hello",+ timestamp: 0,+};++describe("outputExpansionConfigs", () => {+ const [withOutput, withoutOutput, expanded, expandedWithoutOutput] =+ MockNotebook.cellIds();+ const notebook = MockNotebook.notebookState({+ cellData: {+ [withOutput]: {},+ [withoutOutput]: {},+ [expanded]: { config: { expand_output: true } },+ [expandedWithoutOutput]: { config: { expand_output: true } },+ },+ cellRuntime: {+ [withOutput]: { output },+ [expanded]: { output },+ },+ });++ it("expands clamped cells with output and skips cells without output", () => {+ expect(outputExpansionConfigs(notebook, true)).toEqual({+ [withOutput]: { expand_output: true },+ });+ });++ it("clamps expanded cells with output and skips cells without output", () => {+ expect(outputExpansionConfigs(notebook, false)).toEqual({+ [expanded]: { expand_output: false },+ });+ });+});diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsxindex cfc4c29a44..07187375fd 100644--- a/frontend/src/components/editor/actions/useNotebookActions.tsx+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx@@ -7,6 +7,8 @@ import {CheckIcon,ChevronDownCircleIcon,ChevronRightCircleIcon,+ ChevronsDownUpIcon,+ ChevronsUpDownIcon,ClipboardCopyIcon,CodeIcon,CommandIcon,@@ -100,6 +102,7 @@ import type { ActionButton } from "./types";import { useCopyNotebook } from "./useCopyNotebook";import { useRestartKernel } from "./useRestartKernel";import { useSetCodeVisibility } from "./useSetCodeVisibility";+import { useSetOutputsExpanded } from "./useSetOutputsExpanded";const NOOP_HANDLER = (event?: Event) => {event?.preventDefault();@@ -118,6 +121,7 @@ export function useNotebookActions({const [viewState] = useAtom(viewStateAtom);const kioskMode = useAtomValue(kioskModeAtom);const setCodeVisibility = useSetCodeVisibility();+ const setOutputsExpanded = useSetOutputsExpanded();const [resolvedConfig] = useResolvedMarimoConfig();const capabilities = useAtomValue(capabilitiesAtom);const aiEnabled = useAtomValue(aiEnabledAtom);@@ -596,6 +600,22 @@ export function useNotebookActions({handle: () => setCodeVisibility(true, "markdown"),redundant: true,},+ {+ icon: <ChevronsUpDownIcon size={14} strokeWidth={1.5} />,+ label: "Expand all outputs",+ hotkey: "global.expandAllOutputs",+ hidden: viewState.mode !== "edit",+ handle: () => setOutputsExpanded(true),+ redundant: true,+ },+ {+ icon: <ChevronsDownUpIcon size={14} strokeWidth={1.5} />,+ label: "Clamp all outputs",+ hotkey: "global.clampAllOutputs",+ hidden: viewState.mode !== "edit",+ handle: () => setOutputsExpanded(false),+ redundant: true,+ },{icon: <ChevronRightCircleIcon size={14} strokeWidth={1.5} />,label: "Collapse all sections",diff --git a/frontend/src/components/editor/actions/useSetOutputsExpanded.ts b/frontend/src/components/editor/actions/useSetOutputsExpanded.tsnew file mode 100644index 0000000000..9e6a1e1e39--- /dev/null+++ b/frontend/src/components/editor/actions/useSetOutputsExpanded.ts@@ -0,0 +1,67 @@+/* Copyright 2026 Marimo. All rights reserved. */++import { useCallback } from "react";+import {+ getNotebook,+ type NotebookState,+ useCellActions,+} from "@/core/cells/cells";+import type { CellId } from "@/core/cells/ids";+import { isOutputEmpty } from "@/core/cells/outputs";+import { useRequestClient } from "@/core/network/requests";+import type { CellConfig } from "@/core/network/types";+import { Objects } from "@/utils/objects";++/**+ * The `expand_output` config changes needed to expand or clamp every output.+ *+ * Both actions skip cells without output, so their source isn't annotated+ * with a config that has no effect.+ */+export function outputExpansionConfigs(+ notebook: NotebookState,+ expanded: boolean,+): Record<CellId, Partial<CellConfig>> {+ const configs: Record<CellId, Partial<CellConfig>> = {};+ for (const cellId of notebook.cellIds.inOrderIds) {+ const cell = notebook.cellData[cellId];+ if (+ cell === undefined ||+ (cell.config.expand_output ?? false) === expanded+ ) {+ continue;+ }+ if (isOutputEmpty(notebook.cellRuntime[cellId]?.output)) {+ continue;+ }+ configs[cellId] = { expand_output: expanded };+ }+ return configs;+}++/**+ * Hook returning a callback that shows every cell's output in full, or clamps+ * every output to a fixed height, by setting each cell's `expand_output` config.+ */+export const useSetOutputsExpanded = () => {+ const { updateCellConfig } = useCellActions();+ const { saveCellConfig } = useRequestClient();++ return useCallback(+ async (expanded: boolean) => {+ const newConfigs = outputExpansionConfigs(getNotebook(), expanded);++ const entries = Objects.entries(newConfigs);+ if (entries.length === 0) {+ return;+ }++ await saveCellConfig({ configs: newConfigs });++ for (const [cellId, config] of entries) {+ updateCellConfig({ cellId, config });+ }+ },+ [updateCellConfig, saveCellConfig],+ );+};diff --git a/frontend/src/core/edit-app.tsx b/frontend/src/core/edit-app.tsxindex 9c8c48cb07..bbf5085d8f 100644--- a/frontend/src/core/edit-app.tsx+++ b/frontend/src/core/edit-app.tsx@@ -23,6 +23,7 @@ import {useRunStaleCells,} from "../components/editor/cell/useRunCells";import { useSetCodeVisibility } from "../components/editor/actions/useSetCodeVisibility";+import { useSetOutputsExpanded } from "../components/editor/actions/useSetOutputsExpanded";import { CellArray } from "../components/editor/renderers/cell-array";import { CellsRenderer } from "../components/editor/renderers/cells-renderer";import { useHotkey } from "../hooks/useHotkey";@@ -115,6 +116,7 @@ export const EditApp: React.FC<AppProps> = ({const runAllCells = useRunAllCells();const togglePresenting = useTogglePresenting();const setCodeVisibility = useSetCodeVisibility();+ const setOutputsExpanded = useSetOutputsExpanded();// HOTKEYSuseHotkey("global.runStale", () => {@@ -141,6 +143,20 @@ export const EditApp: React.FC<AppProps> = ({useHotkey("global.hideAllMarkdownCode", () => {setCodeVisibility(true, "markdown");});+ useHotkey(+ "global.expandAllOutputs",+ () => {+ setOutputsExpanded(true);+ },+ { disabled: !isEditing },+ );+ useHotkey(+ "global.clampAllOutputs",+ () => {+ setOutputsExpanded(false);+ },+ { disabled: !isEditing },+ );useHotkey("global.collapseAllSections", () => {collapseAllCells();});diff --git a/frontend/src/core/hotkeys/hotkeys.ts b/frontend/src/core/hotkeys/hotkeys.tsindex df7835271e..69f9c757e0 100644--- a/frontend/src/core/hotkeys/hotkeys.ts+++ b/frontend/src/core/hotkeys/hotkeys.ts@@ -389,6 +389,18 @@ const DEFAULT_HOT_KEY = {group: "Editing",key: NOT_SET,},+ "global.expandAllOutputs": {+ name: "Expand all outputs",+ group: "Editing",+ key: NOT_SET,+ additionalKeywords: ["show full output", "unclamp"],+ },+ "global.clampAllOutputs": {+ name: "Clamp all outputs",+ group: "Editing",+ key: NOT_SET,+ additionalKeywords: ["collapse outputs", "shrink outputs"],+ },"global.collapseAllSections": {name: "Collapse all sections",group: "Editing",