Skip to content

feat(nsgo): completions, find, formatting and links in source mode - #291

Merged
bketelsen merged 1 commit into
mainfrom
feat/nsgo-source-editing
Nov 25, 2026
Merged

bketelsen merged 1 commit into
mainfrom
feat/nsgo-source-editing

Conversation

@bketelsen

Copy link
Copy Markdown
Contributor

Summary

The second half (2b) of Phase 2 of plan 0011, "Source mode on NSGo's code editor". Source mode in the NSGo client (cmd/frostnotes-nsgo) now does what the MyGo client's editor does on top of the text. The plain logic is in internal/desktop/markup and internal/desktop/catalog, with unit tests. Each item has a test in the client's suite, against a real notesd.

  1. Completions (links.go, markup.CompletionAt). They use the editor's Completion, CompletionTriggerCharacters ([[, #, ^), OnCompletionRequest and Ref.PresentCompletions.
    • After [[: the vault's files and aliases, in the vault's link format (catalog.NoteSources). The list asks again as the query grows.
    • After [[note#: the note's headings. After [[note#^: its blocks.
    • After #: tags, by count.
    • The client now keeps the vault's catalog, fed by notesd's events. It also reads vault.settings for the link format, the new-note location and Update links.
    • Test: TestCompletionsInSourceMode.
  2. Find and replace in the note (findbar.go). It uses Editor.Search, Ref.Run(FindNext/FindPrevious) and Ref.Replace/ReplaceAll.
    • The bar is made of NSGo's Input, ToggleButton (Match case, Match whole word, Use regular expression), IconButton and Button, on the kit's spacing. It shows "2 of 4", "No results" or "Not a regular expression".
    • Enter and Shift+Enter step through matches. Escape closes the bar.
    • Test: TestFindAndReplaceInTheNote. It covers case, whole word, regexp with ${1}, Replace all as 1 undo step, and Escape.
  3. Formatting commands. markup.Commands holds the 22 that edit text: bold, italics, strike, highlight, code, insert link, checklist, comment, delete paragraph, remove heading and set heading 1 to 6, wikilink, embed, tag, blockquote, bullet and numbered list.
    • The palette (find.go, via editTools in edit.go) also gets Search current file, Search & replace, Indent and Unindent list, Undo, Redo and Follow link under cursor, each with its keys. That makes 29 commands.
    • Commands are applied with Ref.Edit as 1 undo step. A test in internal/desktop/commands checks that the IDs, titles and editor keys match the MyGo client's table.
    • The MyGo client's "Set heading" chooser is not ported. Its 7 commands are.
    • Test: TestFormattingCommandsInSourceMode.
  4. Smart lists and auto-paired marks.
    • Enter and Backspace are bound once the editor has the keyboard, as TestAppKeysAroundTheEditor found. They use markup.ContinueMarkup and DeleteMarkupBackward, and fall back to Ref.Run(editor.Newline) and DeleteBackward.
    • A mark (*_~= and backtick) typed over a selection wraps it (markup.WrapInMark). The editor's typing is undone and the wrap is made as 1 step. If that typing had merged into an earlier undo step, the wrap is completed as a second step instead.
    • Test: TestSmartListsAndMarksInSourceMode. It checks the 1-step undo.
  5. Following the link under the caret. Alt+Enter, Ctrl+click and F12 all go through OnDefinitionRequest. Ctrl over a link underlines it (PresentDefinitionLink).
    • A note link opens the note at its #heading or #^block (markup.SubpathLine, Ref.GoToLine).
    • A heading or block in the same note jumps to its line.
    • An unresolved link creates the note under its own folders, or else where the vault puts new notes (catalog.LinkedNotePath).
    • A tag opens Search vault on tag:#x.
    • Test: TestFollowingLinksInSourceMode. It runs headless as a desktop idiom, because the editor only handles Ctrl+press there; it also passes in GTK.
  6. The inline title (title.go). It sits above the note in both modes. Enter or leaving the field renames the file through the client's existing move (manage.go, catalog.Renamed).
    • If the vault's Automatically update internal links is on, links are updated without asking. If it is off, NSGo's alert asks "Update links?" (Update / Don't update), as the MyGo client does. Closing the alert keeps the old name.
    • Test: TestInlineTitleRenamesTheNote. It checks that another note's link is rewritten on disk.
  7. Multiple selections come from NSGo's editor. mod+Alt+Up/Down and Alt+click add a caret, mod+Shift+L selects all matches, and Escape leaves 1 caret. None of these collide with the app's keys.
    • Test: TestSeveralCaretsInSourceMode.

Ctrl+K: I followed the MyGo client and Obsidian. Inside source mode's editor, mod+K inserts a Markdown link. Everywhere else mod+K stays the palette, and mod+O opens the palette from the editor.

Ctrl+F: inside the editor, mod+F and mod+H open find (and replace) in the note. Anywhere else, mod+F still focuses the notes tree's filter. TestFilterNarrowsTheTree now presses it from the title field.

Keys the editor gives up: NSGo's mod+D (select next occurrence) and mod+L (select line) give way to Obsidian's Delete paragraph and Toggle checkbox status.

Left out

  • Opening a link in a new tab, to the right or in a new window. This waits for Phase 3 (tabs).
  • Web links under the caret. These wait for Phase 8's allow-list, because internal/desktop/system does not build for the web.
  • Links to files that aren't notes. These wait for Phase 5.
  • Smart lists after an input-method composition. NSGo's editor rebinds its own keys after a composition ends. Until the editor next gets focus, Enter and Backspace are its own there. This comes from reading NSGo v0.3.0's code; no test covers it.

Other changes:

  • replaceSource in the tests types line breaks as Shift+Enter, so smart lists don't continue lists.
  • Docs updated: docs/design/app.md (the NSGo section's palette, keys, filter and source mode, plus the live suite) and AGENTS.md (the map's lines for markup and catalog).
  • Plan 0011's status was not edited.

Risk tier

Risk tier: 2 — behaviour change in the NSGo client's editor and its keys. I matched all 33 changed files with a script against .github/risk-paths.json (schema version 2, 22 globs, with braces and ** expanded). None match, so all are at the default level, L3. The change touches no workflow, release, install, secrets or auth path.

Docs housekeeping

  • Cross-links added in both directions (ADR ↔ design ↔ spec ↔ plan): the new text in docs/design/app.md sits in the section that already links plan 0011 and ADR-0049. No new doc.

Verification

  • make check green (host): exit 0 on this tree. It includes make nsgo-check, which runs the headless suite and the wasm build.
  • make nsgo-live green (Xvfb, GDK_BACKEND=x11 from the Makefile): exit 0, 42 passed, 0 failed, 0 skipped. That includes the 7 new tests and Ctrl+click in GTK.
  • make nsgo-bench: exit 0. Source 8.61 ms and live 5.18 ms per keystroke on this host. On main before this change it was 8.3 ms and 5.0 ms (the numbers from feat(nsgo): edit source mode in NSGo's code editor #290).
  • TestNoLiteralLooks passes. No look is written as a number. The title uses workspaceui.Heading(1) and the bar uses the kit's spacing.
  • make nsgo-pictures: 14 PNGs changed. A small Go program compared each one pixel by pixel with main. Every difference is in the editor's pane: the inline title, which pushes the text down. The other 11 came out byte-identical. I looked at note-source, dark-note-live-preview and narrow-note.

The second half of plan 0011's Phase 2: source mode in the NSGo client
gets what the MyGo client's editor does on top of the text.

- Completions on the editor's list: [[ notes in the vault's link format,
  [[note# headings, [[note#^ blocks and #tags by count, from the vault's
  catalog (internal/desktop/catalog), which the client now keeps.
- Find and replace in the note: a bar over source mode on the editor's
  search, with case, whole word and regular expressions; mod+F and mod+H
  in the editor, the notes' filter elsewhere.
- Obsidian's formatting commands (markup.Commands) in the palette and by
  their keys in the editor, applied with Ref.Edit as 1 step of undo.
  Inside the editor mod+K inserts a Markdown link, as in the MyGo client;
  mod+O stays the palette.
- Smart lists on Enter and Backspace, bound once the editor has the
  keyboard, and a mark typed over a selection wraps it.
- Following the link or tag under the caret (Alt+Enter, Ctrl+click,
  F12): a note at its heading or block, a note made for an unresolved
  link, a tag in Search vault.
- The inline title, which renames the note through the client's move,
  asking about links unless the vault updates them.
@github-actions github-actions Bot added the level:L3 Skim label Nov 25, 2026
@bketelsen
bketelsen merged commit 4b66bad into main Nov 25, 2026
15 checks passed
@bketelsen
bketelsen deleted the feat/nsgo-source-editing branch November 25, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants