SelfscribeDownloadOpen the app

06 Editor

Web first, wrapped for desktop. One codebase.

1. Modes

#
ModeWhat the user sees
Sourceplain text with syntax highlighting derived live from the rule table; gutter, line numbers, fold markers, diagnostics squiggles
Hybrid (default)source text where the current line shows its syntax and every other line renders its result in place. This is what Obsidian calls live preview.
Writethe rendered page, edited in place: typing edits the source at the mapped span of the innermost element (D95, D96, D101); code and plugins open their source in a popover
Previewrendered HTML only, as one scroll, as pages like a book, or as slides (set layout, D102)
Splitsource left, preview right, scroll-synced by span

A toggle cycles modes. A size toggle changes the editor font and preview scale independently. In hybrid mode, Show syntax keeps every line as styled source (delimiters visible, muted) and adds rendered widgets only for non-text output (D75). In Write, hybrid and source, a block handle opens the block menu: move, duplicate, delete, and turn into any line or block rule of the document (D95).

2. Implementation basis

#
  • CodeMirror 6. It is the only mainstream editor with incremental decorations,

    a fold service, gutters, a diagnostics API and a proven live-preview pattern. Hybrid mode is a ViewPlugin that replaces ranges with WidgetType decorations, except on lines intersecting the selection.

  • Highlighting does not use a Lezer grammar. It uses the engine's decorations(doc)

    output mapped to CM6 Decoration.mark. When the rules change, the highlighting changes on the next parse. There is no second grammar to keep in sync.

  • Folding uses the engine's fold ranges via a custom foldService.
  • The engine runs in a Web Worker (WASM). Parse is debounced at ~30 ms. The worker returns

    HTML, per-block HTML, decorations, folds, diagnostics and the rule table in one message, with spans already converted to UTF-16 offsets. Decorations and spans travel as typed arrays, and the whole HTML is joined from the blocks on the main thread when read (D76).

  • Hybrid mode renders each top-level block (render_html(doc).blocks) as a widget over its

    span, except blocks intersecting the selection, which show their source.

  • set rules hide makes hybrid mode and preview fold the rules block by default.
  • Any editor extension that needs plugin hints (editor colour, icon) reads them from the

    rule table, so rules stay the single source of truth.

3. Inspector (the DevTools "Styles" panel for rules)

#

Click any rendered element or place the caret in source:

  • Shows the rule that produced the node: file, line, short form, style.
  • Shows the override chain with struck-through overridden rules and their origin

    (built-in, project, workbook, import, document, region).

  • "Edit" jumps to that line in that file. "Override here" copies the rule into the

    current document's rules block for editing.

  • "Import" button opens a picker of built-in templates and project .self files and

    inserts a use line.

4. Rule wizard

#

A dialog that edits one rule in full form with pickers (where, pattern with a slot insert button, target list, modifier checkboxes, a CSS editor with live sample). It writes short form when the rule fits on one line, else full form. It is a formatter over the same AST; no state of its own.

5. Files

#

Web:

  • File System Access API for a single file, a folder (project or workspace), or a

    .zip / .gz workbook. Fallback to download/upload where the API is missing.

  • Optional autosave (debounced, per file, with an on-disk .selfscribe/ state folder

    for tabs and folds only).

  • Recent handles stored in IndexedDB and re-requested on open.

Desktop (Tauri, Rust host): the same UI, native file dialogs, file watching, and the engine called natively instead of through WASM. Tauri is chosen over Electron for size (a few MB) and because the Rust engine is already there.

6. Templates and new document

#

"New" offers: blank Selfscribe, Markdown, BBCode, colour comments, form, workbook. Each is a file in templates/. A new document starts with use NAME rather than a copy of the rules, so the rules block stays uncluttered.

7. Performance rules

#
  • Never block the main thread on parse. Worker only.
  • Hybrid re-render only touches lines whose spans changed.
  • Large documents (50k lines) must stay responsive; decorations are computed for the

    viewport plus a margin, never for the whole document at once.

  • The preview is virtualised too: only blocks near the viewport are in the DOM, anchored to

    the block at the top of the viewport; long lists window their items (D76).

  • GPU-accelerated rendering is out of scope. CM6 with virtualised viewport is enough.
  • Search never blocks: matches are found in slices that yield to the event loop (D78).

8. Search

#
  • Find and replace (Ctrl-F, Ctrl-H) in every mode: match case, whole word, regular

    expression, "n of m", replace, replace all (one undo step), in selection, history.

  • In the preview it searches the rendered text of every block, mounted or not, and

    scrolls the virtual preview to each match; in hybrid mode going to a match reveals its block.

  • Search across files (Ctrl-Shift-F): the open folder or workbook and the open tabs, with

    include / exclude globs; replace across files after a preview and a confirmation.

  • Structure filters use the engine's result, not the source text: in:heading,

    in:code, target:NAME, rule:NAME, section:TITLE, - to exclude (D78).

9. Document styles and view options

#
  • Document styles (set style, 04 §6) render in the preview in full and, in hybrid mode,

    as palette, fonts, width and heading numbers (D79). A style picker (status bar and Manager) with live thumbnails edits the document's set style line, one undo step.

  • View options are editor preferences, not document state: show blank lines, show

    whitespace and tabs, show line endings, indentation guides (preferences.self, D79). They draw only the visible lines.

10. Data views

#
  • Views (04 §7) are interactive in the preview and in hybrid widgets: search, sort, filter

    chips, pagination, virtualised rows for large sources, inline editing per type, board drag, and a form to add or edit a record. Interacting with a view in hybrid mode does not reveal its source.

  • Every edit is a minimal text change to the data block or data file, applied through the

    store as one undo step (D83). The view's own settings stay text: "Save view" rewrites the view: line (or the data block's fence) with the sort, filter and search in use.