Skip to content

Cap rendering and editing of extremely long lines - #607

Open
ollieb-unity wants to merge 1 commit into
AvaloniaUI:masterfrom
ollieb-unity:cap-long-line-rendering
Open

Cap rendering and editing of extremely long lines#607
ollieb-unity wants to merge 1 commit into
AvaloniaUI:masterfrom
ollieb-unity:cap-long-line-rendering

Conversation

@ollieb-unity

Copy link
Copy Markdown

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 TextFormatter shapes every character.

Change

  • VisualLine shapes only the first LENGTH_LIMIT characters and collapses the remainder into a short ... marker via a FormattedTextElement — the same mechanism already 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; TextArea routes CanInsert / GetDeletableSegments through 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-length VisualLineText for over-limit lines.

Builds cleanly against net8.0 and net10.0.

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
danipen self-requested a review August 7, 2026 11:17

@danipen danipen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants