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
improve: Hide code by default for Markdown cells (#2507)
Wasim Sandhu9a674dcb5900
diff --git a/frontend/src/components/editor/cell/code/cell-editor.tsx b/frontend/src/components/editor/cell/code/cell-editor.tsxindex c64a634433..5f5be951ed 100644--- a/frontend/src/components/editor/cell/code/cell-editor.tsx+++ b/frontend/src/components/editor/cell/code/cell-editor.tsx@@ -37,6 +37,7 @@ import { autoInstantiateAtom, isAiEnabled } from "@/core/config/config";import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";import { useSplitCellCallback } from "../useSplitCell";+import { MarkdownLanguageAdapter } from "@/core/codemirror/language/markdown";export interface CellEditorPropsextends Pick<CellRuntimeState, "status">,@@ -325,7 +326,7 @@ const CellEditorInternal = ({};}, [editorViewRef]);- const temporarilyShowCode = async () => {+ const temporarilyShowCode = useCallback(async () => {if (hidden) {updateCellConfig({ cellId, config: { hide_code: false } });editorViewRef.current?.focus();@@ -335,7 +336,17 @@ const CellEditorInternal = ({{ once: true },);}- };+ }, [hidden, cellId, updateCellConfig, editorViewRef]);++ // For a newly created Markdown cell, which defaults to+ // hidden code, we temporarily show the code editor+ useEffect(() => {+ if (code === new MarkdownLanguageAdapter().defaultCode) {+ return;+ }+ temporarilyShowCode();+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [code]);return (<AiCompletionEditordiff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.tsindex cbfce6e831..e72e164db5 100644--- a/frontend/src/core/cells/cells.ts+++ b/frontend/src/core/cells/cells.ts@@ -29,7 +29,11 @@ import { deserializeBase64, deserializeJson } from "@/utils/json/base64";import { historyField } from "@codemirror/commands";import { clamp } from "@/utils/math";import type { LayoutState } from "../layout/layout";-import { notebookIsRunning, notebookQueueOrRunningCount } from "./utils";+import {+ isMarkdown,+ notebookIsRunning,+ notebookQueueOrRunningCount,+} from "./utils";import {splitEditor,updateEditorCodeFromPython,@@ -252,6 +256,10 @@ const {lastCodeRun,lastExecutionTime,edited: Boolean(code) && code !== lastCodeRun,+ config: {+ disabled: false,+ hide_code: isMarkdown(code),+ },}),},cellRuntime: {diff --git a/frontend/src/core/cells/utils.ts b/frontend/src/core/cells/utils.tsindex e551912a0f..340b00e7e9 100644--- a/frontend/src/core/cells/utils.ts+++ b/frontend/src/core/cells/utils.ts@@ -10,6 +10,7 @@ import {type LastSavedNotebook,staleCellIds,} from "./cells";+import { LanguageAdapters } from "../codemirror/language/LanguageAdapters";export function notebookIsRunning(state: NotebookState) {return Object.values(state.cellRuntime).some(@@ -103,3 +104,9 @@ export function getDescendantsStatus(state: NotebookState, cellId: CellId) {runningOrQueued,};}++export function isMarkdown(code: string | undefined) {+ return code && code !== ""+ ? LanguageAdapters.markdown().isSupported(code)+ : false;+}