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(frontend): add show/hide all code commands to command palette (#9989)

Kiran Gadhave5c3d9a994edd
diff --git a/frontend/src/components/editor/actions/useHideAllMarkdownCode.ts b/frontend/src/components/editor/actions/useHideAllMarkdownCode.ts
deleted file mode 100644
index d22707f265..0000000000
--- a/frontend/src/components/editor/actions/useHideAllMarkdownCode.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright 2026 Marimo. All rights reserved. */
-
-import { useCallback } from "react"; /* Copyright 2026 Marimo. All rights reserved. */
-import { getNotebook, useCellActions } from "@/core/cells/cells";
-import type { CellId } from "@/core/cells/ids";
-import { MarkdownLanguageAdapter } from "@/core/codemirror/language/languages/markdown";
-import { useRequestClient } from "@/core/network/requests";
-import type { CellConfig } from "@/core/network/types";
-import { Objects } from "@/utils/objects";
-
-/**
- * Hook to hide all markdown code cells
- */
-export const useHideAllMarkdownCode = () => {
- const { updateCellConfig } = useCellActions();
- const { saveCellConfig } = useRequestClient();
-
- return useCallback(async () => {
- const markdownAdapter = new MarkdownLanguageAdapter();
- const notebook = getNotebook();
- const cellIds = notebook.cellIds.inOrderIds;
-
- const newConfigs: Record<CellId, Partial<CellConfig>> = {};
-
- // Find all markdown cells that aren't already hidden
- for (const cellId of cellIds) {
- if (notebook.cellData[cellId] === undefined) {
- continue;
- }
- const { code, config } = notebook.cellData[cellId];
- if (config.hide_code) {
- continue;
- }
- if (markdownAdapter.isSupported(code)) {
- newConfigs[cellId] = { hide_code: true };
- }
- }
-
- const entries = Objects.entries(newConfigs);
-
- if (entries.length === 0) {
- return;
- }
-
- // Save to backend
- await saveCellConfig({ configs: newConfigs });
-
- // Update on frontend
- for (const [cellId, config] of entries) {
- updateCellConfig({ cellId, config });
- }
- }, [updateCellConfig]);
-};
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index e2c15420bf..f9535e1a55 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -14,6 +14,7 @@ import {
DownloadIcon,
EditIcon,
ExternalLinkIcon,
+ EyeIcon,
EyeOffIcon,
FastForwardIcon,
FileIcon,
@@ -99,8 +100,8 @@ import { LAYOUT_TYPES } from "../renderers/types";
import { runServerSidePDFDownload } from "./pdf-export";
import type { ActionButton } from "./types";
import { useCopyNotebook } from "./useCopyNotebook";
-import { useHideAllMarkdownCode } from "./useHideAllMarkdownCode";
import { useRestartKernel } from "./useRestartKernel";
+import { useSetCodeVisibility } from "./useSetCodeVisibility";
const NOOP_HANDLER = (event?: Event) => {
event?.preventDefault();
@@ -114,7 +115,7 @@ export function useNotebookActions() {
const { selectedPanel } = useChromeState();
const [viewState] = useAtom(viewStateAtom);
const kioskMode = useAtomValue(kioskModeAtom);
- const hideAllMarkdownCode = useHideAllMarkdownCode();
+ const setCodeVisibility = useSetCodeVisibility();
const [resolvedConfig] = useResolvedMarimoConfig();
const capabilities = useAtomValue(capabilitiesAtom);
const aiEnabled = useAtomValue(aiEnabledAtom);
@@ -578,11 +579,33 @@ export function useNotebookActions() {
clearAllCellOutputs();
},
},
+ {
+ icon: <EyeIcon size={14} strokeWidth={1.5} />,
+ label: "Show all code",
+ hotkey: "global.showAllCode",
+ handle: () => setCodeVisibility(false, "code"),
+ redundant: true,
+ },
+ {
+ icon: <EyeOffIcon size={14} strokeWidth={1.5} />,
+ label: "Hide all code",
+ hotkey: "global.hideAllCode",
+ handle: () => setCodeVisibility(true, "code"),
+ redundant: true,
+ },
+ {
+ icon: <EyeIcon size={14} strokeWidth={1.5} />,
+ label: "Show all markdown code",
+ hotkey: "global.showAllMarkdownCode",
+ handle: () => setCodeVisibility(false, "markdown"),
+ redundant: true,
+ },
{
icon: <EyeOffIcon size={14} strokeWidth={1.5} />,
label: "Hide all markdown code",
- handle: hideAllMarkdownCode,
- redundant: true, // hidden by default
+ hotkey: "global.hideAllMarkdownCode",
+ handle: () => setCodeVisibility(true, "markdown"),
+ redundant: true,
},
{
icon: <ChevronRightCircleIcon size={14} strokeWidth={1.5} />,
diff --git a/frontend/src/components/editor/actions/useSetCodeVisibility.ts b/frontend/src/components/editor/actions/useSetCodeVisibility.ts
new file mode 100644
index 0000000000..a8d852603d
--- /dev/null
+++ b/frontend/src/components/editor/actions/useSetCodeVisibility.ts
@@ -0,0 +1,57 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { useCallback } from "react";
+import { getNotebook, useCellActions } from "@/core/cells/cells";
+import type { CellId } from "@/core/cells/ids";
+import { MarkdownLanguageAdapter } from "@/core/codemirror/language/languages/markdown";
+import { useRequestClient } from "@/core/network/requests";
+import type { CellConfig } from "@/core/network/types";
+import { Objects } from "@/utils/objects";
+
+const markdownAdapter = new MarkdownLanguageAdapter();
+
+/** The kind of cell a visibility change applies to. */
+export type CellCodeKind = "code" | "markdown";
+
+const cellCodeKind = (code: string): CellCodeKind =>
+ markdownAdapter.isSupported(code) ? "markdown" : "code";
+
+/**
+ * Hook returning a callback that hides or shows the code editor for every
+ * cell of the given kind.
+ */
+export const useSetCodeVisibility = () => {
+ const { updateCellConfig } = useCellActions();
+ const { saveCellConfig } = useRequestClient();
+
+ return useCallback(
+ async (hidden: boolean, kind: CellCodeKind) => {
+ const notebook = getNotebook();
+
+ const newConfigs: Record<CellId, Partial<CellConfig>> = {};
+
+ for (const cellId of notebook.cellIds.inOrderIds) {
+ const cell = notebook.cellData[cellId];
+ if (cell === undefined || cell.config.hide_code === hidden) {
+ continue;
+ }
+ if (cellCodeKind(cell.code) !== kind) {
+ continue;
+ }
+ newConfigs[cellId] = { hide_code: hidden };
+ }
+
+ 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.tsx
index 0ad3af5057..b983d91e06 100644
--- a/frontend/src/core/edit-app.tsx
+++ b/frontend/src/core/edit-app.tsx
@@ -20,6 +20,7 @@ import {
useRunAllCells,
useRunStaleCells,
} from "../components/editor/cell/useRunCells";
+import { useSetCodeVisibility } from "../components/editor/actions/useSetCodeVisibility";
import { CellArray } from "../components/editor/renderers/cell-array";
import { CellsRenderer } from "../components/editor/renderers/cells-renderer";
import { useHotkey } from "../hooks/useHotkey";
@@ -112,6 +113,7 @@ export const EditApp: React.FC<AppProps> = ({
const runStaleCells = useRunStaleCells();
const runAllCells = useRunAllCells();
const togglePresenting = useTogglePresenting();
+ const setCodeVisibility = useSetCodeVisibility();
// HOTKEYS
useHotkey("global.runStale", () => {
@@ -126,6 +128,18 @@ export const EditApp: React.FC<AppProps> = ({
useHotkey("global.runAll", () => {
runAllCells();
});
+ useHotkey("global.showAllCode", () => {
+ setCodeVisibility(false, "code");
+ });
+ useHotkey("global.hideAllCode", () => {
+ setCodeVisibility(true, "code");
+ });
+ useHotkey("global.showAllMarkdownCode", () => {
+ setCodeVisibility(false, "markdown");
+ });
+ useHotkey("global.hideAllMarkdownCode", () => {
+ setCodeVisibility(true, "markdown");
+ });
useHotkey("global.collapseAllSections", () => {
collapseAllCells();
});
diff --git a/frontend/src/core/hotkeys/hotkeys.ts b/frontend/src/core/hotkeys/hotkeys.ts
index 6ce822717a..07592dd0f7 100644
--- a/frontend/src/core/hotkeys/hotkeys.ts
+++ b/frontend/src/core/hotkeys/hotkeys.ts
@@ -370,6 +370,26 @@ const DEFAULT_HOT_KEY = {
group: "Other",
key: "Mod-j",
},
+ "global.showAllCode": {
+ name: "Show all code",
+ group: "Editing",
+ key: NOT_SET,
+ },
+ "global.hideAllCode": {
+ name: "Hide all code",
+ group: "Editing",
+ key: NOT_SET,
+ },
+ "global.showAllMarkdownCode": {
+ name: "Show all markdown code",
+ group: "Editing",
+ key: NOT_SET,
+ },
+ "global.hideAllMarkdownCode": {
+ name: "Hide all markdown code",
+ group: "Editing",
+ key: NOT_SET,
+ },
"global.collapseAllSections": {
name: "Collapse all sections",
group: "Editing",