Repository navigation
feat(ipynb): render notebooks like a notebook, with seamless click-to-edit cells - #22519
Conversation
Tracebacks and stream output carry terminal colour codes that the notebook printed raw. Splits text into styled runs (16/256/truecolor, bold, italic, underline) and drops non-SGR escapes via the shared stripper.
- Prose inherits the app UI font instead of a bare terminal font name, which Chromium could not resolve and fell back to Times (removes the now-dead resolveEditorFontFamilyOrInherit). - Markdown cells render by default; double-click or Enter edits them in the same Monaco surface code cells use. Code cells activate on press so a collapsing neighbour cannot swallow the click, which also retires the root pointer-capture deactivation (Monaco blur already covers it). - Code sits on its own tinted surface, the active cell gets a ring, and the editor sizes to its content so activating a cell no longer jumps. - The always-on 8-button toolbar and native select become a hover/focus toolbar (move, delete, and a menu for insert and cell type); the Jupyter [n] prompt turns into the run button. - Outputs show only the richest MIME representation, HTML renders in a script-less, no-network sandboxed frame sized to its content, and ANSI colours use the default terminal palettes. Adopts the MarkdownPreviewBody reuse, richest-MIME selection, extra raster MIME ranks, and CSP-sandboxed auto-height HTML frame from #18542. Co-authored-by: maxidiazbattan <[email protected]>
…k header parseIpynb already rejects notebooks without a v4 cells array, so the label carried no actionable information; the parsed nbformat field goes with it. Removes those catalog keys and the stale lowercase code/markdown ones.
The preview and the live editor disagreed on four things, measured over CDP: - Font: the excerpt painted the bare "SF Mono" name (or --font-mono via its row class), while Monaco appended its own fallbacks and landed on Menlo. Both now use resolveEditorFontStack, the editor font plus the terminal fallback chain. - Line height: 20px rows vs Monaco's 21px. Both read CODE_EXCERPT_LAYOUT. - Gutter: a 48px line-number column plus 12px inset vs Monaco's 25px gutter. Notebook cells drop line numbers (the Jupyter and VS Code notebook default) and Monaco's decorations lane is the same 12px inset. - Rows: colorized blank lines collapsed to 0px, and a trailing newline had no preview row. Rows are fixed-height and a trailing newline opens an empty last line, matching the Monaco model. The [n] prompt and run icon now share one grid cell, so the hover swap keeps the label's box and centre. The commented-line tint moves to a theme token.
Replaces the in-place [n]/play swap from 172b4f7. The [n] count is always shown and never moves; the run button sits above it in the same gutter column, revealed on hover or focus from an invisible slot that keeps its box. While a cell runs, the slot shows a spinner and the count reads [*].
…xcerpt unchanged 172b4f7 bent the shared MonacoCodeExcerpt (used by PR comment code context) to the notebook's layout, changing that surface's font, tracking and highlight tint. The excerpt's rendering is now byte-identical to main; only its colorizer is extracted as useMonacoColorizedLines. The notebook renders its own rows from CODE_LAYOUT, the same metrics its Monaco editor uses, so activation stays pixel-stable.
Monaco mounted with its caret at 1:1 and focus ran occurrence highlighting on that first token, so clicking any line lit up every 'import'. The press on the preview now maps to a model position (its rows mirror model lines) and Monaco opens there before focusing; keyboard and markdown activation open at the end. Occurrence highlighting stays on, as in VS Code notebooks.
The [n] count now shares the first code line's box (the gutter mirrors the code surface's border and padding, and the count is one line tall); the run button slot sits beneath it and stays reserved while hidden.
Monaco's colorizer emits theme-specific token classes, so excerpts colorized under one theme kept that theme's token colours after a switch (dark-theme keywords rendered green on the light theme). Affects notebook previews and PR comment code context.
…essly @monaco-editor/react waits on an async loader, shows "Loading..." and builds the editor inside a display:none container. Every click on a cell therefore painted a placeholder, then an editor laid out at 0x0 (one uncoloured line), and the caret guess ran against the static preview, falling back to the end of the cell whenever the press missed a text row (padding, gaps). The cell editor is now created with monaco.editor.create in a layout effect: sized, tokenized (restoring its view state marks the visible lines stable) and placed before the first paint. Monaco hit-tests the press itself with getTargetAtClientPoint, so the caret lands on the nearest position for text, trailing whitespace, blank lines and padding; keyboard and markdown activation open at the start. Indent guides stay off to match the preview. Word and selection occurrence highlighting are off in cell editors, since clicking a word lit up every other occurrence like a search. Also drops wiring the rewrite made dead: the per-editor save shortcut (the notebook's capture handler already owns Cmd+S), the callback refs, the onSaveRequest prop, and the toolbar's positioning wrapper.
useMonacoColorizedLines read the theme once from settings, so a 'system' theme flipping with the OS never re-colorized. It now uses useDocumentDarkTheme, like the rest of the notebook; rendering is unchanged.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughNotebook cells now use a unified source component for preview and editing. Output rendering supports ANSI styling, selects one renderable representation, and displays sanitized HTML in a sandboxed iframe. The viewer layout and toolbar controls have changed. Parser metadata, image MIME ordering, theme handling, font-stack resolution, and related tests and translations were also updated. Merge Risk: 🟡 Moderate · up to A notebook reload can cause an edit to be saved to the wrong cell. Fix that data-integrity risk before merging; the rendering and font regressions also need correction. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description covers the main template sections and provides detailed changes, rationale, issue links, and testing results. It does not provide the required before-and-after visual proof for this UI and interaction change, and the lint, typecheck, and build checklist items remain unchecked.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 1a2ac6a1-bc9b-48e3-8fa4-349c462e2d5b
📒 Files selected for processing (25)
src/renderer/src/assets/main.csssrc/renderer/src/components/editor/IpynbCellEditor.tsxsrc/renderer/src/components/editor/IpynbCellOutputs.tsxsrc/renderer/src/components/editor/IpynbCellToolbar.tsxsrc/renderer/src/components/editor/IpynbHtmlOutput.tsxsrc/renderer/src/components/editor/IpynbRendering.test.tsxsrc/renderer/src/components/editor/IpynbViewer.tsxsrc/renderer/src/components/editor/MonacoCodeExcerpt.tsxsrc/renderer/src/components/editor/ipynb-ansi.test.tssrc/renderer/src/components/editor/ipynb-ansi.tssrc/renderer/src/components/editor/ipynb-code-cell-lines.test.tssrc/renderer/src/components/editor/ipynb-code-cell-lines.tssrc/renderer/src/components/editor/ipynb-parse.test.tssrc/renderer/src/components/editor/ipynb-parse.tssrc/renderer/src/components/editor/use-document-dark-theme.tssrc/renderer/src/i18n/en-runtime-required.jsonsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/i18n/technical-literal-catalog-values.test.tssrc/renderer/src/lib/editor-font-zoom.test.tssrc/renderer/src/lib/editor-font-zoom.ts
💤 Files with no reviewable changes (2)
- src/renderer/src/components/editor/ipynb-parse.test.ts
- src/renderer/src/i18n/en-runtime-required.json
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Important
IpynbHtmlOutput renders untrusted notebook output in a frame that now carries allow-same-origin — the only untrusted-markup frame in the renderer that does, and the opposite of the invariant PluginPanel.tsx documents and tests. Scripts are stripped (DOMPurify) and blocked (no allow-scripts), so it is not a live exploit, but it is a security-boundary change that deserves a deliberate decision before merge. Exact reasoning and alternatives are inline.
Reviewed changes
- Rendered-by-default cells — markdown renders as a document (double-click or Enter to edit); code shows a colorized preview that swaps to a synchronously-created Monaco editor, with the caret hit-tested from the activating press.
- Output rendering — one richest MIME per display bundle, ANSI SGR colors pulled from the terminal theme, and HTML output in a script-free, CSP-fenced frame auto-sized to its content.
- Hover toolbar and run gutter — the eight always-visible buttons become a hover/dropdown toolbar;
[n]sits above a hover run button,[*]while running. - Shared refactor —
useMonacoColorizedLinesextracted fromMonacoCodeExcerptand now re-colors on theme change;resolveEditorFontStackgives notebook code a fallback stack; thenbformatfield and BETA label were dropped.
ℹ️ Nitpicks
config/scripts/locale-ko-key-overrides.json:890still carries an override for the removed keyauto.components.editor.IpynbViewer.59b6cd874b. It is inert (overrides are only looked up when translating an existing key), but it is dead data that the catalog removal should have retired alongside the key.src/renderer/src/lib/editor-font-zoom.ts:1now importsbuildFontFamilyfromterminal-pane/layout-serialization, dragging that module's heavy transitive graph (pane manager, replay guard, crash breadcrumbs) into every editor/diff consumer of this shared helper. Moving the pure string helper to its own small module would keep the layering clean.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| text: string | ||
| error?: boolean | ||
| }): React.JSX.Element { | ||
| function isRenderableMime(mime: string): boolean { |
There was a problem hiding this comment.
isRenderableMime dropped application/javascript, which the old branch rendered as preformatted text, so a display bundle carrying only that MIME now produces no output. Impact is low because kernels normally include a text/plain fallback, but if the removal was incidental, add it back.
The cell's Escape command had no context, so Escape with suggest, find or parameter hints open closed the whole cell editor. It now only fires when none of those widgets is visible.
The output frame had allow-same-origin only so the viewer could measure its content height. Notebook HTML is untrusted, so the frame is now sandbox="" (opaque origin, no scripts) at a fixed height that fits a pandas head() or describe() table and scrolls anything larger.
lib/editor-font-zoom imported it from a terminal-pane component module. The monospace fallback chain now lives in lib, and every importer, including the terminal, points there. Pure move; the tests move with it.
resolveEditorFontStack quoted a value like "JetBrains Mono, monospace" as one family name, which no font matches. A comma list is now used as-is; only a single name gets the quoted fallback chain.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental re-review of the 5 commits pushed since the last Pullfrog review (35a4534..b117538), on top of the full .ipynb notebook redesign. Every change in this delta is a response to prior feedback, plus two follow-up fixes.
- Restored the opaque frame —
IpynbHtmlOutputdropsallow-same-origin; same-origin height measurement is replaced by a fixedh-72scrollable frame, andIpynbRendering.test.tsxnow pinssandbox === ''. This closes the security-boundary concern raised last review and re-aligns with thePluginPanel.tsxinvariant. - Relocated the font helper —
buildFontFamilyand its tests moved from the heavyterminal-pane/layout-serializationmodule to a newlib/monospace-font-family.ts, with every importer (terminal options, appearance, editor font stack) updated. Resolves the layering nitpick. - Escape dismisses widgets first — the cell editor gates its deactivate command behind
!suggestWidgetVisible && !findWidgetVisible && !parameterHintsVisible(all valid Monaco context keys), so a bare Escape leaves the cell while an open suggest/find/signature widget consumes it. - Comma-separated font stacks pass through —
resolveEditorFontStackreturns a user-supplied list unchanged instead of quoting it into a single unknown family name. - Dropped the stale Korean override for the removed
IpynbViewerkey.
One prior inline question remains open and unchanged: isRenderableMime still excludes application/javascript, so a display bundle carrying only that MIME renders nothing (low impact — kernels normally include a text/plain fallback, and the new tests explicitly cover falling back to text for unrenderable MIMEs).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Recreate Monaco when the parsed cell changes. · IpynbCellEditor.tsx:144-239
src/renderer/src/components/editor/IpynbCellEditor.tsx:144-239
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winRecreate Monaco when the parsed cell changes.
IpynbViewerpasses anindex-capturing callback, butIpynbSourceEditorregisters it only once. An external content reload can replace the notebook content while the viewer remains mounted. If the reload changes cell order, the editor can retain the old model and index. A later edit can then draft the cell currently at the old index and persist the edit to the wrong cell.Suggested fix
- // Mount-once: the props it reads cannot change while the cell is being edited. + // Recreate the model when the parsed cell changes, such as after a notebook reload. + // Source-draft updates keep the parsed cell object stable, so typing does not recreate Monaco. useLayoutEffect(() => { @@ - // oxlint-disable-next-line react-hooks/exhaustive-deps -- mount-once; see the Why above. - }, []) + // oxlint-disable-next-line react-hooks/exhaustive-deps -- source drafts update the existing model; parsed cell changes recreate it. + }, [cell])
🟡 Minor · Block file: image sources in notebook Markdown. · IpynbCellEditor.tsx:27-36
src/renderer/src/components/editor/IpynbCellEditor.tsx:27-36
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick winBlock
file:image sources in notebook Markdown.The shared preview preserves
file:URLs, andIpynbMarkdownCelluses the default image renderer. Electronfile:documents can load local files, so an untrusted notebook can display a user-local image. The top-level navigation policy does not block image subresources. This is a localized privacy regression; the evidence does not support code execution or file exfiltration.Suggested fix
-const NO_MARKDOWN_COMPONENTS: Components = {} +const NO_MARKDOWN_COMPONENTS: Components = { + img: ({ src, ...props }) => { + if (typeof src === 'string' && src.toLowerCase().startsWith('file:')) { + return null + } + return <img {...props} src={src} /> + } +}
🟡 Minor · Serialize JSON values before the generic text fallback. · IpynbCellOutputs.tsx:109-127
src/renderer/src/components/editor/IpynbCellOutputs.tsx:109-127
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winSerialize JSON values before the generic text fallback.
When a display bundle contains only
application/jsonwith an array of objects,parseDisplayItemspreserves the array.DisplayItemsends it tovalueToText, which converts each object to[object Object]. Keep JSON handling MIME-specific so line-array text output remains unchanged.Suggested fix
if (item.mime.startsWith('image/')) { const uri = dataUriForImage(item) return uri ? ( <img src={uri} alt={item.mime} className="mx-3 max-h-[520px] max-w-full self-start object-contain" /> ) : null } + if (item.mime === 'application/json' || item.mime.endsWith('+json')) { + const text = + typeof item.value === 'string' ? item.value : JSON.stringify(item.value ?? null, null, 2) + return <TextOutput text={text} /> + } if (item.mime === 'text/markdown') { return <IpynbMarkdownCell source={valueToText(item.value)} /> }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 12b89cf5-c0df-4607-ab2a-4b06fa4a6304
📒 Files selected for processing (15)
config/scripts/locale-ko-key-overrides.jsonsrc/renderer/src/components/dashboard-popout/preview-terminal-options.tssrc/renderer/src/components/editor/IpynbCellEditor.tsxsrc/renderer/src/components/editor/IpynbHtmlOutput.tsxsrc/renderer/src/components/editor/IpynbRendering.test.tsxsrc/renderer/src/components/settings/TerminalSettingsPreview.lifecycle.test.tsxsrc/renderer/src/components/settings/TerminalSettingsPreview.tsxsrc/renderer/src/components/terminal-pane/layout-serialization.test.tssrc/renderer/src/components/terminal-pane/layout-serialization.tssrc/renderer/src/components/terminal-pane/terminal-appearance.tssrc/renderer/src/components/terminal-pane/terminal-pane-manager-options.tssrc/renderer/src/lib/editor-font-zoom.test.tssrc/renderer/src/lib/editor-font-zoom.tssrc/renderer/src/lib/monospace-font-family.test.tssrc/renderer/src/lib/monospace-font-family.ts
💤 Files with no reviewable changes (3)
- src/renderer/src/components/terminal-pane/layout-serialization.test.ts
- config/scripts/locale-ko-key-overrides.json
- src/renderer/src/components/terminal-pane/layout-serialization.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/editor/IpynbCellEditor.tsx
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| // Append each fallback unless already present (case-insensitive) to avoid duplicates. | ||
| for (const fallback of FALLBACK_FONTS) { | ||
| const lower = fallback.toLowerCase() | ||
| if (!lowerParts.some((p) => p.includes(lower))) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Preserve the generic monospace keyword.
When the configured family is monospace, Line 21 quotes it as a named font. This substring check then omits the unquoted generic fallback. The editor can select a different installed font instead of the configured system monospace font. Keep a standalone monospace unquoted, and suppress the generic fallback only when that keyword is already present unquoted. Add a test for monospace and for a font name that contains that word.
Proposed fix
- const parts = trimmed ? [`"${trimmed}"`] : []
+ const parts = trimmed
+ ? [trimmed.toLowerCase() === 'monospace' ? 'monospace' : `"${trimmed}"`]
+ : []
...
- if (!lowerParts.some((p) => p.includes(lower))) {
+ if (!lowerParts.some((p) => (fallback === 'monospace' ? p === lower : p.includes(lower)))) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (!lowerParts.some((p) => p.includes(lower))) { | |
| if (!lowerParts.some((p) => (fallback === 'monospace' ? p === lower : p.includes(lower)))) { |

ELI5
Opening a Jupyter notebook in Orca used to look like a form: serif text, raw markdown next to its preview, code cells that blended into the background, and eight buttons on every cell. Now it reads like a notebook in Jupyter or VS Code. Markdown is rendered, code sits in its own box, and you click a cell to edit it.
What Changed
Before → after, as the user sees it:
[n]is always shown. A run button appears under it on hover (VS Code layout), and[*]shows while a cell runs.How it works:
monaco.editor.createin a layout effect, so it's sized, tokenized and has its caret placed before first paint. Monaco places the caret by hit-testing the real click (getTargetAtClientPoint). Previously,@monaco-editor/reactmounted asynchronously behind a placeholder, and the caret position was guessed from the preview.MonacoCodeExcerpt, used by PR review comment code context, renders as before. Its colouring moved into auseMonacoColorizedLineshook, which now also re-colours on theme change.Unchanged: cell execution (
src/main/ipc/notebook.ts) and its model of re-running earlier cells. A real kernel is a separate follow-up.Why
This builds on community PR #18542 by @maxidiazbattan. It keeps that PR's shared markdown renderer, richest-MIME selection, extra image formats and sandboxed HTML output, and simplifies the rest.
It drops the global Preview/Edit mode toggle. That flag was threaded through several components and silently disabled Cmd+S. Rendered-by-default with click-to-edit is what Jupyter and VS Code do, and it needs no mode state.
Creating Monaco synchronously was chosen over keeping the preview painted until an async editor was ready. The alternative needs a "painted" state and still gets the caret position by guessing.
Linked Issue
Fixes #17075
Supersedes #18542
Visual Proof
Not attached. The change was reviewed interactively in a dev build against a real 35-cell notebook, in dark and light themes, and compared side by side with Jupyter Notebook and VS Code's notebook editor.
Testing
Rendered checks over CDP in dark and light themes, including frame captures across a real click and box measurements. Code box, first glyph,
[n]and run button move 0px across idle, hover and editing.The caret lands correctly with real mouse input: on a character, right of a line, on a blank line, and in the padding.
Preview and editor token colours match across repeated theme switches and reloads.
Edits save as valid notebook JSON; Cmd+S inside a cell works.
MonacoCodeExcerptoutput was compared against main with the same props and is identical.pnpm tc,pnpm test(editor, github, lib: 7,797 tests),check:code-quality:changed, oxlint, oxfmt,verify:localization-*.Tested on macOS only.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
MonacoCodeExcerptrefactor (rendering unchanged, plus the theme re-colour fix), a new font-stack helper used only by notebooks, two CSS rules scoped to.ipynb-code-surface, and removal of now-unused notebook i18n strings.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)