Skip to content

add editable code in slide view#9389

Merged
Light2Dark merged 7 commits intomainfrom
sham/add-code-editor-toggle
Apr 29, 2026
Merged

add editable code in slide view#9389
Light2Dark merged 7 commits intomainfrom
sham/add-code-editor-toggle

Conversation

@Light2Dark
Copy link
Copy Markdown
Collaborator

@Light2Dark Light2Dark commented Apr 26, 2026

📝 Summary

  • Press C or the code icon to toggle a code editor under/above the slide element. I've edited the CSS to make it work within a slide.
  • This is a global toggle, pressing C will turn it on for all slides. This toggle is not persisted, by default it is false.
  • Works in fullscreen mode. In read-mode, a readonly code editor is used instead.
Screen.Recording.2026-04-27.at.1.20.50.PM.mov

run mode (with include-code)
image

Follow-up PRs:

  • Add some docs or guide in the sidebar to show that users can do this

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 27, 2026 6:09am

Request Review

@Light2Dark Light2Dark added enhancement New feature or request bash-focus Area to focus on during release bug bash labels Apr 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an editable code editor to slide view so presenters can toggle code visibility and run cells directly from the deck, while keeping islands (read-only embeds) bundles slim via a build-time stub/alias.

Changes:

  • Introduces SlideCellView (CodeMirror editor + output + run/stop/status) and wires it into the Reveal slides renderer behind a “Show code” toggle (+ C keybinding).
  • Extracts shared “needs run” and status-class logic into frontend/src/core/cells/utils.ts and reuses it in notebook cells and slide cells.
  • Updates islands build to alias @/components/slides/slide-cell-view to a no-op stub, and updates slides smoke-test examples/layouts to exercise the new behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
marimo/_smoke_tests/slides_examples/nested_slides.py Adds additional cells (tables) to the nested slides example; minor refactors in markdown cell.
marimo/_smoke_tests/slides_examples/layouts/nested_slides.slides.json Extends slide layout to include a new sub-slide + fragments sequence.
marimo/_smoke_tests/slides_examples/kitchen_sink.py Bumps generated version, tweaks headings, adds an iframe slide example.
frontend/src/core/islands/stubs/slide-cell-view.tsx Build-time stub to keep slide editor dependencies out of islands bundles.
frontend/src/core/cells/utils.ts Adds cellNeedsRun and cellStatusClasses helpers.
frontend/src/components/slides/slide-form.tsx Stops keydown propagation in sidebar to prevent reveal.js navigation while interacting.
frontend/src/components/slides/slide-cell-view.tsx New slide cell renderer with editable editor + output + run controls.
frontend/src/components/slides/reveal-slides.css Styles CodeMirror within slides.
frontend/src/components/slides/reveal-component.tsx Adds code toggle UI/keybinding and renders SlideCellView when code is shown.
frontend/src/components/editor/renderers/slides-layout/slides-layout.tsx Removes external deckRef plumbing; enables slide editing based on mode.
frontend/src/components/editor/notebook-cell.tsx Reuses extracted cellNeedsRun / cellStatusClasses.
frontend/islands/vite.config.mts Uses ESM-safe dirname resolution; adds alias to stub out slide editor in islands build.
Comments suppressed due to low confidence (1)

marimo/_smoke_tests/slides_examples/nested_slides.py:481

  • After inserting the new cells above, this comment’s cell numbering is now out of sync with the actual file/layout (the closing slide is no longer cell 22). Updating the numbering/labels will help keep the slide layout JSON and this annotated example aligned.
@app.cell(hide_code=True)
def _(mo):
    # Cell 22 (slide) — closing slide.
    mo.md(

Comment thread marimo/_smoke_tests/slides_examples/nested_slides.py
Comment on lines +229 to +245
@app.cell
def _(mo):
_bios_df = {
"first_name": ["Jane", "Alex", "Doe", "Maria", "Li", "Omar"],
"last_name": ["Smith", "Johnson", "Brown", "Garcia", "Wei", "Ali"],
"age": [29, 35, 42, 28, 31, 45],
"occupation": [
"Data Scientist",
"Product Manager",
"Software Engineer",
"UX Designer",
"Researcher",
"Entrepreneur",
],
"location": [
"San Francisco, CA",
"New York, NY",
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _bios_df table data is duplicated verbatim across multiple consecutive cells. This adds a lot of noise to the slides example and makes future edits error-prone. Consider defining the dataset once (e.g., in an earlier cell that returns it, similar to how secret is shared) and reusing it in the downstream table cells.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to showcase how a large code editor would look like

@Light2Dark
Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review

@cubic-dev-ai
Copy link
Copy Markdown

cubic-dev-ai Bot commented Apr 27, 2026

@cubic-dev-ai review

@Light2Dark I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 15 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="frontend/src/core/meta/__tests__/code-visibility.test.tsx">

<violation number="1" location="frontend/src/core/meta/__tests__/code-visibility.test.tsx:38">
P1: Don't redefine `window.location` in jsdom; use `history.replaceState` to update `search` and restore the original URL instead.</violation>
</file>

<file name="frontend/src/core/islands/stubs/slide-cell-view.tsx">

<violation number="1" location="frontend/src/core/islands/stubs/slide-cell-view.tsx:18">
P1: Missing `SlideCellReadOnlyView` export. The real module exports both `SlideCellView` and `SlideCellReadOnlyView`, and `reveal-component.tsx` statically imports both. This stub only provides `SlideCellView`, so `SlideCellReadOnlyView` will be `undefined` in the islands bundle. Add the stub for both exports to avoid a potential runtime crash and to keep the module contract consistent.</violation>
</file>

<file name="frontend/src/components/slides/reveal-component.tsx">

<violation number="1" location="frontend/src/components/slides/reveal-component.tsx:290">
P2: The "C" key binding is registered only once in `handleDeckReady` (which fires on the deck's `onReady` event). If `codeToggleEnabled` is `false` at that moment but later becomes `true` (e.g., in read mode when cell code loads asynchronously), the keyboard shortcut will never work — only the button will. Consider registering the binding unconditionally in `handleDeckReady` (since `codeShown` already guards rendering) or adding an effect that calls `addKeyBinding`/`removeKeyBinding` when `codeToggleEnabled` changes.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant User
    participant RevealComp as RevealSlidesComponent
    participant RevealJS as reveal.js API
    participant CellView as SlideCellView
    participant Editor as CellEditor (CodeMirror)
    participant Kernel as Python Kernel

    Note over User,Kernel: Initialization & Configuration

    RevealComp->>RevealComp: useNotebookCodeAvailable()
    Note right of RevealComp: Checks mode, kiosk status,<br/>and include-code query param

    RevealComp->>RevealJS: NEW: addKeyBinding('C', toggleShowCode)
    
    Note over User,Kernel: Toggle Code Flow

    User->>RevealJS: Press "C" or Click Code Icon
    RevealJS->>RevealComp: toggleShowCode()
    RevealComp->>RevealComp: SET showCode = !showCode

    alt NEW: showCode is TRUE
        RevealComp->>CellView: Render SlideCellView
        
        alt Mode is "Edit" or "Present"
            CellView->>Editor: NEW: Initialize Editable Editor
            Editor-->>CellView: Display Source Code
        else Mode is "Read"
            CellView->>CellView: NEW: Render SlideCellReadOnlyView
        end
    end

    Note over User,Kernel: Interactive Execution (Editable Mode Only)

    opt If isEditable is True
        User->>Editor: Edit code + Ctrl/Cmd+Enter
        Editor->>Kernel: NEW: runCell(cellId, code)
        Kernel-->>CellView: Update Cell Runtime State
        CellView->>CellView: CHANGED: Render Output (Above/Below)
        
        Note right of CellView: Uses cellOutputPosition<br/>from UserConfig
    end

    Note over RevealComp,RevealJS: Layout Synchronization
    
    RevealComp->>RevealJS: NEW: triggerResize()
    Note right of RevealJS: Ensures slide content fits<br/>with editor visible
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread frontend/src/core/meta/__tests__/code-visibility.test.tsx
Comment thread frontend/src/core/islands/stubs/slide-cell-view.tsx
Comment thread frontend/src/components/slides/reveal-component.tsx
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Comment thread frontend/src/core/islands/stubs/slide-cell-view.tsx
@Light2Dark Light2Dark marked this pull request as ready for review April 27, 2026 06:09
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 15 files

Architecture diagram
sequenceDiagram
    participant U as User
    participant R as RevealSlidesComponent
    participant RV as Reveal.js (Deck)
    participant CV as useNotebookCodeAvailable
    participant SV as NEW: SlideCellView
    participant CM as CellEditor (CodeMirror)
    participant K as Marimo Kernel

    Note over U,K: Slide View Initialization
    R->>CV: Check code availability (mode, URL params, cells)
    CV-->>R: codeToggleEnabled
    
    opt codeToggleEnabled is true
        R->>RV: NEW: addKeyBinding('C', toggleShowCode)
    end

    Note over U,K: Toggle Code Flow (Press 'C' or Click Icon)
    U->>R: Trigger toggleShowCode()
    R->>R: NEW: update showCode state (via startTransition)
    
    alt showCode is TRUE
        R->>SV: NEW: Render SlideCellView (for active slide)
        SV->>CM: Mount CodeMirror instance
        R->>RV: CHANGED: triggerResize() (adjust for editor height)
    else showCode is FALSE
        R->>SV: Unmount SlideCellView
        R->>RV: triggerResize()
    end

    Note over U,K: Runtime Execution from Slide
    U->>CM: Edit Python code
    U->>CM: Cmd+Enter / Click Run
    CM->>SV: runCell(cellId)
    SV->>K: Send execution request
    K-->>SV: Cell output/status update
    SV->>SV: CHANGED: update cellStatusClasses (needsRun, errored, etc.)

    Note over U,K: Read-Only / Island Boundary
    alt Mode is "read"
        R->>SV: NEW: Render SlideCellReadOnlyView
        SV->>SV: Render syntax-highlighted static block
    else Is Island/Static Export
        Note over R,SV: Build-time stubbing replaces SlideCellView with null
        R->>CV: returns false (isIslands() check)
    end
Loading

@Light2Dark Light2Dark changed the title add code editor in slide view add editable code in slide view Apr 28, 2026
Copy link
Copy Markdown
Contributor

@peter-gy peter-gy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks and works great

@Light2Dark Light2Dark merged commit 7a83d3f into main Apr 29, 2026
47 checks passed
@Light2Dark Light2Dark deleted the sham/add-code-editor-toggle branch April 29, 2026 13:24
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.5-dev6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants