Repository navigation
Fix(tui): sequence, class and ER diagrams lose nothing in the preview - #41
Merged
Merged
Conversation
A left-to-right flowchart wider than the pane was cut off with no way to see the rest, and its labels kept their source quotes. Width was only part of it: the library's text layout routes no edges, so its boxes overlap, an edge back to an earlier node and every edge label are dropped, and a branch is drawn through the boxes between. zn now keeps the library's parser and draws flowcharts and state diagrams itself: a row of boxes when a left-to-right diagram fits, otherwise a column with wrapped labels. An edge to the box drawn next is an arrow between them, and any other edge is listed under its source by the name of its target. Parsing is cached by content and only the layout follows the width. The parser ends a quoted label at its first closing bracket and loses the edge after it, drops a label given after a node's first use, and skips spellings like `A -- yes --> B`. zn works around these. When a statement still cannot have been read in full, the block shows its source and says so. Sequence, class and ER diagrams still come from the library, and show their source when they do not fit. Tables and aliases in the reading view had bugs of their own. In the default style, aliased links pushed column rules out of line and a wrapped alias showed its token brackets. In the zen style, an alias's pipe split the cell, wide cells were cut off, and tables with no outer pipes did not render. `[[Note\|alias]]` now follows Note, not `Note\`.
The library's text drawings lose content at any pane width. A long sequence message is clipped, and notes and blocks are dropped. An ER diagram drops its relationships and a class diagram their types, labels and method arguments. ER and class order also changes from one parse to the next. A sequence diagram is now drawn only when it has just participants and plain `->>` or `-->>` messages, each label comes out whole, and it fits. Other sequence diagrams, and all class and ER diagrams, show their source with a note. The preview's 10-column minimum cut letters off every row in a very narrow pane, so wrapping now follows the pane. This applies to all preview content.
Review of the first version found a panic and diagram content lost with no note. A label holding the runes zn used to hide quoted text ended the app, so zn now picks runes the note does not hold. IDs that start with a keyword, like title-bar, vanished with their edges. `A --o B --> C` drew a false edge label. The read-in-full check now compares the edges and the node IDs of each statement, for every statement that can name one, so a circle or cross edge, trailing words and a statement word used as an ID show the source. Quote marks open only where a label can start and no longer pair across statements, arrows inside a label stay text, and `A-->B[x]` with no spaces is read as an edge. A second label for a node and a group never closed show the source too. Two nodes with one label show their IDs, and an empty label shows its ID. In the reading view, a note's own token brackets and hard spaces are kept, a table cell's padding goes at its end, and a zen table only protects pipes inside a real wikilink.
… into claude/interesting-poincare-c5d579 # Conflicts: # internal/tui/mermaidtext_test.go
A fence the note never closes kept losing its last statement with no note, in every diagram type. The last line is now dropped only when it closes the fence. An embedded CRLF note no longer puts carriage returns in rows, and a `%%` comment holding a semicolon no longer forces the source. A sequence diagram now shows its source for a late or repeated alias, a label with a wide letter, combining mark, tab or control character, a name holding an arrow, an `actor`, or a `<br` in a message. The drawing is also capped before the library allocates its grid, so 2,000 participants by 2,000 messages stays small. Math source wraps rather than ending in an ellipsis, which the lower preview minimum had made more likely. A diagram with no nodes yet shows its source instead of vanishing.
adibhanna
changed the base branch from
claude/tui-mermaid-width-28f594
to
main
November 4, 2026 22:34
…th (#39) Mermaid text diagrams were cut off at the pane's edge, and the library's text layout also dropped edge labels and edges back to earlier nodes. zn keeps the library's parser and now draws flowcharts and state diagrams itself: a row of boxes when one fits, otherwise a column with wrapped labels. Any edge not drawn between neighbouring boxes is listed under its source. A statement the parser cannot read in full shows the block's source with a note, so nothing goes missing without saying so. IDs in any script, comments, entities and the common edge spellings are read. Tables in the reading view also change. Aliased links keep columns in line, and a wrapped alias shows no token brackets. In the zen style an alias stays in one cell, wide cells wrap, and tables with no outer pipes render.
Note text now shows as text and does not act on the terminal. The filter lives in internal/termsafe and runs on every TUI frame and, when stdout or stderr is a terminal, on CLI output. Pipes and files keep every byte. The editor, both reading views and the views that list note text draw a control rune as a one-cell picture such as a visible ESC, so the cursor stays on its rune and a note's own colours stay out of the terminal. Opening a note with bytes that are not valid UTF-8, or with CRLF line ends, no longer marks it changed, so quitting leaves the file as it is until a real edit. Very long words are broken before Glamour, whose word wrap is quadratic in a word's length.
1 task
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.
Stacked on #39, so this targets its branch. Retarget to
mainonce #39 merges.The library's text drawings of sequence, class and ER diagrams lose content at any pane width, even when the diagram fits. #39 only falls back to the source when one is wider than the pane.
What the library loses
a really long message about t). Notes,loop/altblocks,autonumber, titles and activations are dropped.-x,-)and->draw like->>.A<<->>Bcreates a participant calledA<<.parser->>dbloses the message because the parser reads aparblock. Non-ASCII labels get gaps (hé llo wö rld).|o,o|and}orelationships never parse.+eat(a) voidbecomes+eat: void(). From the renderer and parser code, static and abstract marks, namespaces and notes are dropped, andA<|--BandA <-- Bdo not parse.ER and class order comes from a Go map, so it changes between parses. It is not alphabetical, as first reported.
What changes
participantlines and plain->>or-->>messages, when the parser agrees with each statement, every label comes out whole with each character one cell wide, and the drawing fits. Anything else shows the source with a note, includingactor, a late or repeated alias,<brin a message, and a name holding an arrow. A drawing over about 1 million cells also shows the source, before the library allocates its grid.![[...]]no longer puts carriage returns in rows.…, which the lower minimum below would otherwise make more likely.renderPreviewhad a 10-column minimum that cut letters off every row. It is now 1. This affects all preview content, not just Mermaid.zenstyle shows every Mermaid block as code. That renderer never calls the Mermaid drawing code, and this change does not alter that.Known limits
%%{init}%%andclassDiagram-v2show the source under an "invalid mermaid header" error. All the content is there, but the error is misleading.Testing
go test ./...andgo vet ./...pass, and the Mermaid tests pass with-race. The new tests failed before the fix, exceptTestMermaidPlainSequenceIsStillDrawn, which guards behaviour that should not change.zenat 120. That run predates the review fixes, which are covered by tests only.mmdcwere not run in a real Kitty terminal. That code is unchanged.