Repository navigation
Cap rendering and editing of extremely long lines - #607
Merged
maxkatz6 merged 2 commits intoOct 26, 2026
Merged
Conversation
A single very long line (e.g. a minified blob or a Unity YAML asset with an inline binary payload serialized as hex) froze the UI thread as it scrolled into view: TextMate tokenized and colorized the whole line, and TextFormatter shaped every character. - VisualLine shapes only the first LENGTH_LIMIT characters and collapses the remainder into a short "..." marker (a FormattedTextElement, the same mechanism used for collapsed fold regions). Document offsets are unchanged, so caret, selection and highlighting keep working. - TextMateColoringTransformer skips tokenizing/colorizing lines past LENGTH_LIMIT. - New LongLineEditProtection disallows edits inside the collapsed tail, and TextArea routes CanInsert/GetDeletableSegments through it so callers cannot insert into or delete the hidden region (deleting the delimiter would merge the next line into the hidden text). Co-authored-by: Daniel Penalba <daniel.penalba@unity3d.com>
danipen
self-requested a review
August 7, 2026 11:17
Collaborator
|
@maxkatz6 can you merge this one? Solving the conflicts now... |
Resolve VisualLine conflict: long lines run the RunsOnLongLines generators (tab layout) over the first LENGTH_LIMIT characters, then collapse the rest into the LENGTH_LIMIT_MARKER element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Done! |
3 tasks done
OleRoss
added a commit
to rosslight/Darp.CodeEditor
that referenced
this pull request
Nov 5, 2026
## Summary
The editor package had its document model but no control. This PR
implements `CodeEditor`, `CodeEditorStyles` and `CodeEditorViewState` on
AvaloniaEdit, with TextMate highlighting that colors the visible lines
first and tokenizes the rest in the background.
```xml
<Application.Styles>
<FluentTheme />
<ce:CodeEditorStyles />
</Application.Styles>
```
```csharp
var editor = new CodeEditor { Document = CodeDocument.Create(CodeLanguage.Json, json) };
CodeEditorViewState state = editor.SaveViewState(); // before switching documents
editor.RestoreViewState(state); // follows the edits made since
```

| The context menu takes the editor's theme variant | Typing recolors at
once |
| --- | --- |
| 
| 
|
## Changes
- Where to look: `CodeEditor.cs` (showing a document only while in the
visual tree, disposal, view state, `ScrollTo`), `Highlighting/` (the
background highlighter, one TextMate registry per editor) and
`CodeEditorStyles.axaml`.
- AvaloniaEdit comes from a preview feed, `12.0.999-ci3-alpha`, with
three fixes not yet released upstream: each control uses its own
dispatcher, the undo history no longer keeps editors alive, and the last
focused element is held weakly. Restoring it needs a token with
`read:packages` (`CONTRIBUTING.md`); CI reads
`AVALONIAEDIT_PACKAGES_TOKEN`.
- Long lines: the background tokenizes any line within 50 ms; a line
that runs out of time stays uncolored and the next one starts from the
grammar's start. One slow call on the UI thread leaves only that line to
the background.
- The built-in XML grammar now tokenizes: VS Code's file has begin rules
without an end, which are read the way vscode-textmate reads them.
TextMateSharp is updated to 2.0.5.
- `ScrollTo`'s doc now says "taller or wider than the view".
### Benchmarks
The latency budgets of `docs/design.md` 1.2 are tracked by benchmarks,
not asserted by tests (decision 102). Pull requests compare only the
`CI` category against the target branch, six cases instead of 21:
| Benchmark | Guards |
| --- | --- |
| `FirstFrameBenchmarks.FirstColoredFrame` | highlighted text soon after
creating an editor |
| `TypingBenchmarks.KeystrokeIn5000Lines` | the UI thread while typing |
| `TypingBenchmarks.KeystrokeOnA20000CharacterLine` | the long-line
freeze the prototype had |
| `ScrollingBenchmarks.PageDown` | the UI thread while scrolling |
| `HighlightingBenchmarks.TokenizeAllLinesWarm` | background tokenizing
throughput |
| `DocumentBenchmarks.EditAndSnapshot` | the cost of one edit |
`--filter '*'` still runs all of them locally (`CONTRIBUTING.md`). Main
has no editor yet, so this PR's benchmark comment shows the editor
benchmarks without a comparison; later PRs compare them. The workflow
now packs the target branch outside the checkout, so that it restores
with its own `nuget.config`.
## Testing
- Added tests for the editor's contracts: selection, caret position,
`ScrollTo`, view state across edits, read-only, clipboard, keys reaching
the app, disposal (also while attaching), two editors on one document,
collection after removal, themes by variant and fallback, and
highlighting of each built-in language. They pass with `dotnet test` and
as a NativeAOT executable.
- Ran the editor in a desktop app on Linux, as in the screenshots:
highlighting, typing, the context menu, and a `ThemeVariantScope`.
- Not covered: editors on a second UI thread (decision 100 stays), and
the first editor of a fresh JIT process, which takes about 450 ms,
mostly Avalonia's and AvaloniaEdit's first use (decision 103).
## Impact
- Restoring the repository needs the preview feed's token until
AvaloniaEdit releases the fixes. Pull requests from forks can't restore
it.
- Lines over 3,000 characters show only their start and can't be edited
past it: AvaloniaEdit's upstream AvaloniaUI/AvaloniaEdit#607, which the
preview includes. An upstream option to raise the limit is in progress.
## Checklist
- [x] Documentation (and changelog) is updated if needed
- [x] CI Pipeline is successful
- [x] (Human) Self-review was done
PR generated by claude-opus-5-5
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.
Problem
A single very long line — e.g. a minified blob, or a Unity YAML asset with an inline binary payload serialized as hex — freezes the UI thread as it scrolls into view. Two full-line passes run synchronously: TextMate tokenizes and colorizes the whole line, and
TextFormattershapes every character.Change
VisualLineshapes only the firstLENGTH_LIMITcharacters and collapses the remainder into a short...marker via aFormattedTextElement— the same mechanism already used for collapsed fold regions. Document offsets are unchanged, so caret, selection and highlighting keep working.TextMateColoringTransformerskips tokenizing/colorizing lines pastLENGTH_LIMIT.LongLineEditProtectiondisallows edits inside the collapsed tail;TextArearoutesCanInsert/GetDeletableSegmentsthrough it so callers cannot insert into or delete the hidden region (deleting the line delimiter would otherwise merge the next line into the hidden text).This builds on the existing
VisualLine.LENGTH_LIMIT(3000) short-circuit, which previously still added a single full-lengthVisualLineTextfor over-limit lines.Builds cleanly against
net8.0andnet10.0.