Skip to content

feat(desktop): editable Markdown editor for workspace .md files — source-fidelity (CodeMirror + Streamdown), not TipTap #862

Closed

Description

@softmarshmallow

Summary

Grida Desktop renders .md / .markdown files read-only (Streamdown), the same way it renders images and video. There is no way to edit a markdown file in the workspace — the only editable mode the editor pane ships is .svg. This issue proposes promoting markdown from a viewer to an editable mode, parallel to the SVG editor.

The interesting part is which editor model — and the answer is not the rich-text editor we already have (TipTap). The defining property of our .svg editor is source fidelity (load → edit → save round-trips to byte-identical markup); the faithful markdown analog of that is a source editor, not a WYSIWYG rich-text surface that normalizes the user's file on every save. This issue grounds that decision and maps it onto the seams that already exist.

Scope note: description + design proposal for later pickup, not a fix.

Background — what exists today (grounded)

  • Markdown is read-only. detectFileMode() routes .md / .markdown → { kind: "markdown" } → MarkdownViewer, which just wraps <Streamdown> over the file text. (editor/scaffolds/desktop/workbench/editor-pane-tab.tsx:166,249; editor/scaffolds/desktop/workbench/editor-pane-viewers.tsx:116-133.)
  • .svg is the only editable mode. The dispatcher's one writable branch is EditorPaneSvgEditor (editor-pane-tab.tsx:137-146). Mode routing is a hardcoded extension switch — not a registry — so adding an editable markdown mode is a local edit to detectFileMode + a new case "markdown-editor".
  • The SVG editor's contract is source fidelity. @grida/svg-editor parses SVG into an in-memory IR that preserves source trivia (attribute order, quoting, whitespace, comments); editor.serialize() round-trips it back to identical markup, and editor.load(content) re-seeds from disk (editor-pane-svg-editor.tsx:196,220). The file on disk is the source of truth.
  • The save / dirty / conflict machinery is already built and reusable. EditorPaneSvgEditor's Surface (editor-pane-svg-editor.tsx:117-280) implements the full feat(desktop): watch workspace files — refresh open editor + file tree on external change, with save-conflict guard (VSCode model) #805 model: content_version vs savedVersion → dirty badge; Cmd+S gated on active; an mtime precondition on workspaces.writeFile (commitWrite, line 163) with isWriteConflict → a Keep editing / Reload from disk / Overwrite anyway dialog; and useWorkspaceChanges for non-dirty auto-reload / dirty-defer. A markdown editor reuses this wholesale — none of it is SVG-specific.
  • We already render markdown well. Streamdown (streamdown@^2.5.0) + @streamdown/{cjk,code,math,mermaid} plugins are wired in agent chat (editor/kits/agent-chat/message.tsx:31-34) — code highlighting, CJK segmentation, LaTeX math, and Mermaid all render today. The read-only MarkdownViewer uses the plain <Streamdown> default. This is the natural preview half of an editor.

The core design question: which editor model?

The naive move is "we already have TipTap (@tiptap/*@^2.11.7, editor/kits/minimal-tiptap/) — reuse it." That is the wrong tool for a .md file editor, and the reason is exactly the property the SVG editor exists to guarantee.

TipTap's canonical model is ProseMirror (HTML-shaped rich text); markdown is a lossy import/export format bolted onto it, not the model. Open a .md → parse to a ProseMirror doc → edit → serialize back, and every save rewrites the user's source: collapses whitespace, normalizes *↔_ emphasis and -↔* bullets, flattens reference-style links, and silently drops anything it doesn't model — YAML frontmatter, footnotes, HTML blocks, MDX/JSX, comments. For a file editor where the .md is the artifact, that is the precise opposite of @grida/svg-editor's "preserve source trivia, round-trip byte-identical" guarantee. TipTap's correct home — form fields and CMS rich text, where the canonical store is the rich model and not a file on disk — is where it already lives; the fact that it's an existing dependency is gravity, not a reason to put it on .md files.

The honest analogy breaks on the format itself: SVG's source is machine-authored XML edited visually; markdown's source IS the human-authored artifact. Authors expect to control the raw text (this is how Obsidian, GitHub, VS Code, and Bear all edit markdown). So the source-fidelity-preserving parallel to the SVG editor is a source editor with live preview, not a syntax-hidden WYSIWYG.

Library evaluation

Option Model Round-trip fidelity In repo? Verdict
CodeMirror 6 + Streamdown preview edits raw markdown text; preview re-rendered from text Perfect by construction (you edit the bytes) No (new, small dep) Recommended v1. Faithful to the SVG editor's value; reuses Streamdown for preview; what serious md tools do.
TipTap (ProseMirror) rich-text doc; md as export Lossy — normalizes/drops syntax on every save Yes (^2.11.7) Rejected for file editing. Breaks source fidelity. Keep it in forms/CMS.
Milkdown (ProseMirror, md-first) markdown AST is the model Good (principled, some normalization) No Reach for this only if syntax-hidden WYSIWYG is a hard requirement.
MDXEditor (Lexical, built for .md) markdown AST; handles frontmatter/JSX/tables Good No WYSIWYG alternative to Milkdown; Lexical-based.
Monaco text Perfect Yes (^0.47.0) Works, but heavyweight (VS Code core) for a markdown pane; CodeMirror is the lighter, md-idiomatic choice.

Proposed architecture (recommended)

CodeMirror 6 source pane + existing Streamdown preview, split. Mirror EditorPaneSvgEditor exactly — only the edit surface and serialization differ, and serialization is trivial (the text is the document):

EditorPaneMarkdownEditor  (clone of editor-pane-svg-editor.tsx)
┌──────────────────────────────────────────────────────────────┐
│  load: workspaces.readFile → { content, mtime }                │
│                                                                │
│   CodeMirror 6 (source)        │   Streamdown (preview)         │
│   @codemirror/lang-markdown    │   <Streamdown> + cjk/code/     │
│   - edits raw text             │     math/mermaid plugins       │
│   - dirty = doc != saved       │   - re-rendered from buffer    │
│                                                                │
│  save (Cmd+S): writeFile(…, expectedMtime) → mtime token       │
│  conflict: Keep editing / Reload / Overwrite   (reused #805)    │
└──────────────────────────────────────────────────────────────┘
  • Serialization is identity — no IR, no normalization, no dropped syntax. editor.serialize() is view.state.doc.toString(); editor.load(content) is a setState/dispatch. Round-trip fidelity is automatic.
  • Reuse feat(desktop): watch workspace files — refresh open editor + file tree on external change, with save-conflict guard (VSCode model) #805 wholesale — content_version/savedVersion dirty tracking, the mtime-precondition save guard, isWriteConflict → the Keep/Reload/Overwrite dialog, and useWorkspaceChanges non-dirty-reload. For markdown the "Compare" omission that the SVG editor lives with is less of a compromise — a text diff would actually be meaningful here later.
  • Reuse Streamdown — the preview half already exists and is consistent with how the agent renders markdown.
  • Live preview later — CodeMirror's decoration API can grow toward Obsidian-style inline preview (hide syntax as you type) incrementally, without changing the source-of-truth model.

If syntax-hidden WYSIWYG is later deemed a hard requirement, switch the edit surface to Milkdown or MDXEditor (both keep the markdown AST as the model — far cleaner than TipTap) — but that is a deliberate fidelity trade, not the default.

Key design decisions (settle during planning)

  1. Source vs. WYSIWYG. The one decision that flips the library choice. Source-visible (the markdown author's default expectation) → CodeMirror. Syntax-hidden WYSIWYG → Milkdown/MDXEditor. Recommend CodeMirror source + preview for v1. Either way: not TipTap.
  2. Layout of source vs. preview. Split pane (side-by-side), toggle (edit ⇄ preview), or source-only with a preview toggle? VS Code defaults to source with an openable preview; a split is the most discoverable for a design tool. Start with a toggle to keep v1 small.
  3. Headless package or not. @grida/svg-editor is a standalone headless package because its IR is non-trivial. A CodeMirror source editor is already headless (core + React binding) — a @grida/markdown-editor package is over-engineering for v1 and only earns its keep if/when we build the WYSIWYG/IR variant. Recommend: no new package; wire CodeMirror directly in the pane, like the viewers.
  4. Streamdown plugin parity. Use the same cjk/code/math/mermaid plugin set as agent chat (message.tsx:31-34) for the preview, so a doc renders identically whether the agent prints it or the user previews it.
  5. Frontmatter / MDX. A source editor shows these verbatim (a feature). Decide whether the preview should parse frontmatter (hide it / render a table) or show it raw. v1: show raw, render body.
  6. New mode wiring. Add { kind: "markdown-editor" } to FileMode and split: keep MarkdownViewer for a read-only path if useful (e.g. a preview-only toggle), or replace the .md route entirely with the editor. Recommend replacing the route; the editor's preview half subsumes the viewer.
  7. Agent-as-concurrent-writer. Same as the SVG editor — the agent can edit an open .md. The feat(desktop): watch workspace files — refresh open editor + file tree on external change, with save-conflict guard (VSCode model) #805 machinery already handles this (non-dirty reload / dirty-defer / save-guard); markdown inherits it for free.

Affected files

Concern File
Mode dispatch (.md → editor) editor/scaffolds/desktop/workbench/editor-pane-tab.tsx (detectFileMode, FileMode, ModeBody)
New editable pane new editor/scaffolds/desktop/workbench/editor-pane-markdown-editor.tsx (clone of editor-pane-svg-editor.tsx)
Preview rendering editor/scaffolds/desktop/workbench/editor-pane-viewers.tsx (MarkdownViewer → reused as preview half)
Save / dirty / conflict (reused) editor-pane-svg-editor.tsx is the template; bridge workspaces.writeFile(…, expectedMtime) + isWriteConflict already exist
Editor dependency editor/package.json — add @codemirror/state, @codemirror/view, @codemirror/lang-markdown, @codemirror/commands (theme to match)
(only if WYSIWYG) headless pkg new @grida/markdown-editor — defer; not needed for source mode

Proposed minimal scope (v1)

  1. CodeMirror 6 source editor for .md / .markdown, dispatched via a new markdown-editor mode in detectFileMode.
  2. Streamdown preview (same plugin set as agent chat) behind an edit ⇄ preview toggle.
  3. Reuse the SVG editor's save/dirty/conflict machinery verbatim — Cmd+S, dirty dot, mtime guard, Keep/Reload/Overwrite.
  4. Defer: split-pane live preview, Obsidian-style inline preview decorations, frontmatter parsing, a WYSIWYG (Milkdown/MDXEditor) variant, a headless @grida/markdown-editor package.

References

Activity

  1. added
    enhancement
    desktop
    on Jun 17, 2026
  2. added a commit that references this issue on Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    desktopenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions