Repository navigation
feat(nsgo): edit source mode in NSGo's code editor - #290
Merged
Merged
Conversation
Source mode in the NSGo client is NSGo's code editor (nsgo/ui/editor v0.3.0) on the note's document, in place of a multiline field: the first half of plan 0011's Phase 2. - The undo rule (ADR-0022; ADR-0049, decision 3): typing reaches the document through Document.Local. Any other change of its text (a merge, another writer's change, a reload) never enters the editor as a new value, which NSGo records as an undo step: the editor starts again on the new text with its carets, folds and first line in view mapped through the change, so Ctrl+Z never takes back another writer's change. - Obsidian's highlighting for the lines in view: markup.Highlight, a UI-free port of the MyGo client's overlay, in NSGo's palette. - Folds by headings, the frontmatter and indentation (markup.Folds), no line numbers, indentation guides, tabs of 4 with hard tabs, paired brackets, soft wrap and a readable line length of 700: the MyGo client's defaults. - make nsgo-bench, the typing gate on NSGo, in source mode and live preview, with desktop-bench's note and limits. CI does not run it yet. - A test records which keys an app binding takes before the editor.
frostyard-machines
approved these changes
Nov 25, 2026
6 tasks done
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
The first half of Phase 2 of plan 0011 ("Source mode on NSGo's code editor"). Source mode in the NSGo client was a multiline
ui.Input. It is now NSGo's code editor (github.com/nsgo-dev/nsgo/ui/editor, v0.3.0), bound to the note'snotes.Document(cmd/frostnotes-nsgo/source.go).Document.Local. NSGo's editor records any newValueas an undo step, and it cannot keep an edit out of its history or clear the history. So any other change of the document's text (a merge, another writer's change, a reload, a load after a failed one) never goes into the live editor. Instead the editor starts again (core.Dynamicon a start counter,DefaultValue) on the new text. Its selections, folds and first line in view are mapped throughnotes.Diff(old, new)withChangeSet.MapPosand set again withRef.SetSelections,SetFoldsandSetScrollOffsetonce the new editor is laid out. The user's undo history ends there. If typing reaches the old editor before it restarts, that typing is mapped over the other writer's change (ChangeSet.Map). The editor also restarts when the note becomes editable or read-only. Tests:TestUndoNeverTakesBackAnotherWritersChange(another writer's change to a saved note, then a notesd merge of an unsaved edit; Ctrl+Z leaves both and undoes only typing done after them) andTestAnotherWritersChangeKeepsTheCaretAndTheView. When the remote change was instead put into the editor withRef.SetValue, the first of these tests failed; it was run once that way.Highlighterfor the lines in view. It runs off the UI goroutine and wrapsmarkup.Highlight, a UI-free port of the MyGo client'seditor/syntax.gooverlay that also lexes the Markdown MyGo's own lexer used to provide. It covers frontmatter (fences, keys, values), headings, emphasis, strong, strike, code spans, fenced and indented code, Markdown links, URLs and autolinks, wikilinks, embeds and images, tags, highlights,%%comments across lines, callouts, footnote references and definitions, inline and$$block math, block IDs, quote and list marks, and rules. What is open at a line (frontmatter, a fence, indented code, math, a comment) is read from the lines before it. The colors come from NSGo's palette by kind. NSGo v0.3.0 maps an app's token kinds by name (KindNamed) and has no bold or italic kind for them, so the text of emphasis and strong keeps the text color and only its marks are dimmed.markup.Folds, an O(n) port of MyGo'sFoldEnd; a#inside a fence is not a heading), throughFoldRanges. The other settings are the MyGo client's defaults: no line numbers, indentation guides, tab size 4, indenting with tabs, paired brackets and soft wrap. They are copied in the client becauseprefsimportssystem, which the web build cannot build, andTestSourceTakesTheMyGoDefaultschecks they still equalprefs.Default(). The settings UI is Phase 7.readableWidth).TestNoLiteralLookspasses, and no other look is written as a number.make nsgo-benchrunsBenchmarkTypingInALongNoteincmd/frostnotes-nsgo/bench_test.go. It uses the same 10,000-line note and the same limits asdesktop-bench(16 ms, or 25 ms withCI=true, ADR-0043), in source mode at the note's end and in live preview on its first line, headless, against a real notesd. A keystroke is one step ofnsgotesttyping one character: the key and the edit reach the focused field, the client does its work (the editor inserts, the document takes the edit, the folds are worked out again, or in live preview the lines are scanned again), and the host runs what was posted and commits the views that changed to its model of the window. No pixels are drawn, so GTK's layout and painting are not included, and highlighting runs off the UI goroutine. The run then saves the note and checks that the file on disk holds every keystroke. On this host (AMD Ryzen AI Max+ 395): source 8.3 ms, live 4.8–5.0 ms.make desktop-benchon the same host: MyGo source 2.0 ms, live 8.4 ms.desktop-benchstays, and CI does not runnsgo-benchyet: wiring it into.github/workflows/is L2 and is left for a later PR.TestAppKeysAroundTheEditor, passes headless and in GTK). For a key, the newest binding runs, and the editor binds its keys when it gets the keyboard. A binding made around the editor before that gets mod+V, which the editor does not bind, but does not get Enter or Backspace, which the editor handles. A binding made after the editor has the keyboard (in aShowon its focus, placed after the editor) gets all three, and the editor does nothing with them. Smart lists in 2b can bind that way and callRef.Run(editor.Newline)/DeleteBackwardwhen they have nothing to do. Paste would then have to read the clipboard itself; the editor's own paste goes through its field'sOnPaste, which is internal.Out of scope (2b): completions, find and replace, formatting commands, smart lists and auto-paired marks, following links, the inline title, multiple-cursor commands. Live preview is unchanged.
Other changes: the tests read source mode's text from the editor's rows (
sourceText), because the editor's field keeps no value. On a target, line breaks in source mode are typed as Enter keys (replaceSource). Committing them through an input method turned them into spaces in GTK, and a line break inside typed text left the previous line in the editor's field, so it was typed a second time. The web build now links chroma's lexers throughnsgo/base/editor, sogo-sources.jsonwas regenerated.docs/design/app.md(NSGo section and live suite) andAGENTS.mdwere updated. Plan 0011's status was not edited.Risk tier
Risk tier: 3 —
Makefilematches.github/risk-paths.json(L2, governance). I matched all 24 changed files with a script against the schema-2 globs, expanding braces and**; the other 23 files are at the default level, L3. The Makefile change only adds a new target,nsgo-bench(ago test -tags integration -run '^$' -bench …incmd/frostnotes-nsgo, withDISPLAYandWAYLAND_DISPLAYunset as innsgo-check). It changes no existing target and adds nothing toverify,check,ciorbump.internal/repocheckaccepts the-runfilter because the run carries theintegrationtag, andmake checkpasses.Docs housekeeping
docs/design/app.mdlinks plan 0011, ADR-0022, ADR-0043 and ADR-0049Verification
make checkgreen (host): exit 0 on the final treemake nsgo-livegreen (Xvfb,GDK_BACKEND=x11from the Makefile): exit 0, 35 passed, 0 failed, 0 skipped, on the final treemake nsgo-bench: exit 0 (source 8.38 ms, live 4.99 ms per keystroke)make flatpak-sourcesrun, for the change tocmd/frostnotes-nsgo/go.modandgo.summake nsgo-pictures: 9 PNGs changed in pixels and are committed (note-source,dark-note-source, the 4 dialog pictures,narrow-note,dark-narrow-note,narrow-menu: each shows source mode). A small Go program compared each one withmainpixel by pixel, and every difference is inside the editor's area. The other 16 came out byte-identical. I looked atnote-source,dark-note-sourceandnarrow-note.TestUndoNeverTakesBackAnotherWritersChangefails when the remote change is put into the editor withRef.SetValueinstead of restarting the editor