Repository navigation
Replace the Markdown preview with a Live editor and list editing keys - #110
Merged
Merged
Conversation
Markdown file tabs open in a Live view: one editable text view over the source, formatting applied as attributes from Foundation's parser with source positions, and markup glyphs left ungenerated on every line the caret is not on. Source keeps the monospaced editor with its ruler and Wrap toggle. The core tab field is markdown_live; the read-only preview, its empty-document state and its tests are gone, and the conversation ledger keeps its own renderer as ConversationMarkdown. Documents over 256 KB open in Source with Live disabled and a notice. Parsing runs off the main thread, one in flight, with a burst of edits coalescing into one more; attributes are re-applied only where the plan changed. Heading sizes, the quote rule and the italic skew are HideTheme tokens, and the design canvas carries the Live board.
A plain-text NSTextView keeps one attribute set for its whole storage and re-applies its typing attributes to all of it, which turned a document into the heading the caret was in. The view is rich text now, with paste and drop limited to plain strings so a clipboard's fonts never reach it.
Glyph generation asked for the first hidden marker with a linear scan on every call, which cost 57 ms of main-thread time per keystroke on a 10,000-line document; the search it already had brings that to 7 ms.
Opening a 10,000-line document peaked at two gigabytes: every span resolved its font by descriptor and copied a paragraph style, and the background parse autoreleased tens of megabytes that a worker thread never drained. Attribute sets are cached per style, and both the parse and a whole-document apply run inside an autorelease pool; the peak is now flat across the open and sixty keystrokes.
…arkdown Enter after an item's text starts the next item with the same marker or the next number; on an empty item it removes the marker and leaves the list; a lone numbered marker stays as typed. Tab and Shift-Tab move an item one level and a numbered item counts in the column it joins, while the column it left renumbers. Backspace on an empty item removes only its marker. A marked composition falls through to the composer. The rules are pure functions over the source text shared by the Live and Source views, so the file ends up as ordinary Markdown.
Keeps the document-kind adapters from main and replaces their Preview branch with the Live editor; the design canvas carries both the document kinds board and the Markdown live board.
The test slept a fixed 700 ms for a 450 ms debounce and failed when a loaded machine stretched the save past the wait. Poll the file with the suite's eventually helper so the assertion follows the save.
Opening the 8000-paragraph fixture in Source blocked the main thread for about ten seconds: the highlighter applied every run without batching the backing storage, so each setAttributes ran processEditing over the whole document, and the layout of 32,000 lines followed. Every other main-actor test's timer landed behind that block, which is what made the autosave test fail. Batch the highlighter's storage edits and build the fixture from wide paragraphs so the test stays over the byte limit at 240 lines.
…view # Conflicts: # design/hide.pen # docs/README.md # scripts/pen-token-map.json
Context trimmed the caret line's ending with a Character-based dropLast, and Swift treats CRLF as one Character, so a CRLF file lost the last character of the line on every list key and the rewritten lines came back with LF. Read the line content through NSString, carry the carriage return into every rewritten line, and leave a line ending the "\n"-indexed lines cannot place to the text view.
Every heading level is semibold, so h5 and h6 differ from the body by weight and not from each other; the comment claimed weight carried the level.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NSTextViewwhose text storage is the source, with headings, bold, italic, strikethrough, inline code, fenced code blocks, lists, quotes, links and thematic breaks drawn in place and their markup glyphs hidden by anNSLayoutManagersubclass. The caret line and every line a selection touches show the raw markup; the rest stays formatted. The read-only Preview mode (MarkdownPreview.swift,MarkdownDocumentTests) is gone; the toolbar group is "Live / Source" and the core's per-tab field ismarkdown_live(runtime only, a reopened tab starts Live).AttributedString(markdown:)with source positions (MarkdownLiveSource.plan(for:)), runs off the main thread once per change with pending changes coalesced, and applies attributes on the main thread without touching the string. A file over 256 KB opens in Source with both mode buttons disabled and the notice "Live preview is off for files over 256 KB". A parse failure keeps the source monospaced, puts the reason in the notice and does not block input.-/n.item, Enter on an empty item clears the marker and renumbers below, Tab and Shift-Tab move one level (two spaces) with renumbering, Backspace on an empty item removes the marker only, a lone1.line stays as typed, and none of it runs during a Korean composition.MarkdownListEditingis pure functions over the text;MarkdownListKeyswires them into the Live text view and, only for Markdown, into the Source editor (CodeEditorTextView).openDocumentLink(http(s) external, checkout-relative files revealed, otherwise the existing notice); a plain click places the caret.MarkdownPreview.swiftmoved toConversationMarkdown.swiftunchanged in behavior.DESIGN.mddescribes the two modes and the list rules;design/hide.pengainsScreen / Editor / Markdown live(formatted, caret line, code block, empty document, over 256 KB) on eight new tokens (Editor.headingFontSizes,Editor.quoteRuleWidth,Editor.italicSkew) added toHideTheme.setAttributesinsidestringStorage.beginEditing/endEditing(each run was runningprocessEditingover the whole document, seconds on a few hundred KB), andFileDocumentStateTestspolls for the autosave instead of sleeping a fixed 700 ms past a 450 ms debounce.Related
agents/prd/markdown-live-preview/prd.md(B1-B22, D-01..D-14; amendment 1 added B16-B22 and D-14)mainduring the run: PR Open PDFs in the file viewer and add Explorer open items for the default app and a browser pane #107 (document kinds,EditorViewerOverlay.swiftkind switch) and PR Open Explorer single clicks in a replaceable preview tab #108 (editor preview tab). The Explorer, preview-slot andfiles.rscode is byte-identical tomain.Breaking change
markdown_previewis renamedmarkdown_liveand thefile_viewevent payload with it. The value was never persisted (per tab, runtime only), so no state directory or saved setting changes; a shell and core are always built together from this tree.Review focus
apple/swift-markdownwas not vendored. One quirk handled inMarkdownLiveSource: after a multi-line code span Foundation keeps reporting the same line number while the byte offsets stay right, so the plan builder trusts offsets, not lines.- [ ]) are not treated as list items so they stay raw source (B6).HighlightedCodeEditorgainedmarkdownListEditingso Source mode of a Markdown file follows the same keys (B22); other languages are untouched.macos/Sources/HerdrMacOS/MarkdownLiveEditor.swift: the text view is rich text (isRichText = true) withreadablePasteboardTypes = [.string]; a plain-textNSTextViewapplies typing attributes to the whole storage after an edit, which rewrote the document in the H1 font once during native QA and is now pinned byeditingInsideAHeadingLeavesTheBodyAtItsOwnSizeandpastingRichTextBringsOnlyItsCharacters. The parse is versioned so a stale result never applies, and a result arriving during an IME composition is dropped and re-parsed on commit.macos/Sources/HerdrMacOS/MarkdownLiveSource.swift: the span/marker plan built from Foundation's source positions (1-based lines, UTF-8 byte columns) mapped to UTF-16 ranges; thematic breaks carry their newline so the hairline draws from the paragraph's first glyph.macos/Sources/HerdrMacOS/MarkdownListEditing.swift: the renumbering column logic (renumber(_:column:around:)) bounded by shallower items and blank lines, andContext.init, which reads the caret line throughNSStringand carries a CRLF line's\rinto every rewritten line (the Code review found the first version dropping a character on CRLF files; fixed in17058c5with tests).macos/Vendor/Highlightr/src/classes/CodeAttributedString.swift: five lines in vendored code; the outerbeginEditingwas already there, the inner storage's was not.main's from PR Open Explorer single clicks in a replaceable preview tab #108. Does a physical single click open a preview tab onmainfor you? If not, that is Open Explorer single clicks in a replaceable preview tab #108's, not this branch's, but it is worth knowing before both land.Risk surface
Mutex<Runtime>; the core change is the field rename. Parsing and styling live in the shell.editor.tabs[].markdown_liverides the existing revisioned editor tab record wheremarkdown_previewrode; thefile_viewevent carries{tab_id, markdown_live, wrap}.file_viewwhen the user changes it; the Live view reads the draft and writes it back through the sameupdateDraft/scheduleFileSavepath as Source, and holds no mirrored state.localizedDescriptionunder the toolbar and the source stays monospaced and editable; an over-limit file is the fixed notice with both mode buttons disabled; a link that cannot open is the existingopenDocumentLinknotice. Nothing is logged for a parse failure beyond the notice, because it is per keystroke and recoverable.plan(for:)on a worker thread (coalesced: at most one in flight and one pending), one attribute restyle of the changed region and one hidden-marker refresh on the main thread. Measured on a 10,000-line / 224,706-byte document in the debug build (agents/runs/markdown-live-preview/perf/REPORT.md, 60 keystrokes with a caret move each): main-thread insert p50 6.6 ms / p95 10.6 ms / max 16.8 ms, caret move p50 4.7 ms / p95 4.9 ms, changed-region apply p50 5.9 ms, keystroke-to-formatted p50 238 ms (parse-bound;-Oparse is ~65 ms). Physical footprint peak stays at the process baseline (377 MB) across the burst; before the fixes in37ca71fand5c55a3aan insert cost 57 ms p50 and sixty keystrokes grew the process by a gigabyte. Native: idle 1.4% CPU with the document open, 125% CPU during the driven burst. Regression owners:MarkdownLiveEditorTests(formatting, reveal, IME, paste, list keys) andMarkdownLiveSourceTests(plan ranges), plus the threshold recorded in the report (insert and caret p95 under 16 ms at 10,000 lines, flat footprint).Evidence
b45a67d,1bdce49,eb14476andc9e36b6, isolated Herdr 0.9.1 server, fixture with notes.md, README.md, empty.md, big.md 300 KB, long.md 10,000 lines; 39 registered artifacts in the local run directory, fonts read throughAXAttributedStringForRange, text and caret through AX, key semantics through CGEvents with the app frontmost):•bullets and numbers with indent, the quote rule, the---hairline, and the table, task box and image kept as monospaced source.#,**, backticks and fences (inside a block the whole block reveals; outside, the fence lines collapse); typing Korean and English mid-line lands at the caret and the neighbouring lines stay formatted; Source shows the typed source verbatim; every typed character reached the file through autosave../README.mdswitched to the README tab; Cmd-click on./nope.mdshowed "The linked file is missing or outside this checkout."long.mdopen and 60-keystroke burst in the native app sampled idle and driven.- oneand1. onelists produced the PRD's outcomes and the saved file is plain Markdown (bytes checked withod); CRLF documents are covered bycrlfLinesKeepTheirEndingsAndEveryCharacter(value tests), not driven live.markdown_preview,MarkdownPreview.swiftorMarkdownDocumentTestsin the tree;node scripts/check-design-contract.mjs,gen-pen/check-penpass with the board present.310b29a:verify-cargo.sh test786 passed,verify-swift.sh test484 passed (4.2 s),verify-cargo.sh lint, every CONTRIBUTING check script that runs unattended (design contract, pin single source, schema-only contract, no-attribution, no-workstation-identity, core-bridge structure, typed contractgenerated/structure, and the rest),check-hide-copy.mjsagainst0a138f9: the only inventory change ismarkdown-preview→markdown-liveplusmarkdown-live-unavailable(accessibility identifiers).aFailedParseLeavesTheSourceMonospacedWithTheReason; Foundation's parser did not fail on any fixture, so it was injected.setMarkedText; a live Korean composition was typed, but Enter/Tab during an uncommitted composition was not driven by synthetic events.openDocumentLink's existing code.plan(for:)was timed with-O(65 ms p50). Scrolling and selection drag on the 10,000-line document were not measured.c9e36b6bundle under synthetic input (see the reviewer question); files were opened through ⌘P instead.agents/runs/markdown-live-preview/live/shots/, indexed inINDEX.md, registered in the verification report by name, sha256 and observation); none is attached to this public PR.Deterministic verification
agents/runs/markdown-live-preview/verification-report.json, attempt 9 at head310b29a, generated 2026-09-19)58088e7a1ed0e13a02a6807a2ea99ce5ac940d2454ed81a1d9178f317e02db68, basea233c6a(implement start), head310b29a(merged withorigin/main0a138f9atc9e36b6)bash scripts/verify-cargo.sh test, S2 GREENbash scripts/verify-swift.sh test, S3 GREENbash scripts/verify-cargo.sh lintAgent review
1bdce49, re-confirmed forf98a6e3,c9e36b6and310b29a; both report no Fix-now item at310b29a, the Fidelity reviewer moved B20 to MET on the orca citation, and the Code reviewer reran its CRLF reproductions against the fix).MarkdownListEditing.Context.initCRLF corruption:String.dropLast(2)on a line ending indropped one Character (the CRLF grapheme) plus the last content character, so every list key on a CRLF file lost a character and flattened the line ending. Fixed in17058c5: the line content comes fromNSString.getLineStart(_:end:contentsEnd:for:), the carriage return is re-appended to every rewritten line, any other terminator makes the key fall through to the text view, andMarkdownListEditingTestsgained CRLF and foreign-terminator cases (the reviewer's two reproductions included).1.kept as text only for a sole top-level item): kept as implemented. D-14 rule 6 names orca's handling as the rule; orca'scommitEmptyOrderedListMarkerAsText(rich-markdown-list-continuation.ts) applies only when the ordered list has one item and is not nested in a list item, which is the shipped guard. The PRD sentence summarises that rule without the qualifier; a human may overrule by broadening the guard.MarkdownListEditing.renumber/belongswalk the contiguous run of the column on every list key (O(n) in the list's length, main thread); fine for ordinary lists, worth a cap if very long ordered lists turn out common (Code).isSoleIteminspects only the adjacent lines, an engineering reading of orca'schildCount === 1over a source text; a human with orca open may want to confirm (Fidelity).HideThemewas reworded in310b29a; H5 and H6 remain the same size and weight, which no requirement distinguishes (Fidelity).AI tooling
손으로 확인한 것: the font runs, caret positions and saved bytes quoted above were read from the running app through the accessibility API and compared against the PRD's strings and the DESIGN.md sizes; the PR text was checked against the diff, not the PRD's intent.