Skip to content

Support appending/replacing text (parts) to a TextDisplay#140

Merged
dhardy merged 10 commits into
masterfrom
push-vprosqpzukyn
May 31, 2026
Merged

Support appending/replacing text (parts) to a TextDisplay#140
dhardy merged 10 commits into
masterfrom
push-vprosqpzukyn

Conversation

@dhardy

@dhardy dhardy commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds lower-level methods for adding text to a TextDisplay, supporting adding a text in parts. Also supports replacing text parts.

Motivation

The existing design is a poor fit for text editors and potentially also for viewing large documents for performance reasons: it requires (re)-preparing all text at once.

This new API supports splitting a source text at line-breaks and adding each part independently, appending to or replacing old content.

Currently text-wrapping and alignment must still happen for all content afterwards; this could be addressed in the future (if necessary) but is relatively cheap.

@dhardy dhardy force-pushed the push-vprosqpzukyn branch from e4b6f9c to 92360ce Compare May 31, 2026 08:27
@dhardy

dhardy commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

The motivation for this didn't quite work out for text editors since highlighting information also needs to be updated piecemeal, then matched up to the TextDisplay at run-time: it therefore makes sense to use a separate TextDisplay for each "piece" of text.

One (minor) feature is needed now: the ability to turn off imply_empty_final_line.

I will merge this PR anyway because (in my opinion) it fits well into kas-text and may eventually find some other uses.

API change summary

New pub methods on TextDisplay:

  • clear(self)
  • runs_len(self) -> usize
  • append_runs(self) -> RunAppender
  • replace_runs(self, range) -> RunReplacer`

Changed pub methods on TextDisplay:

  • resize_runs has an additional range parameter; pass .. to achieve old behaviour

New pub struct RunAppender has pub methods:

  • push_text(self, text, font_tokens, imply_empty_final_Line) -> Result<(), NoFontMatch>
  • push_text_range(self, text, range, font_tokens, imply_empty_final_Line) -> Result<(), NoFontMatch>

New pub struct RunReplacer has pub methods:

  • index() -> usize
  • push_text(text, font_tokens, imply_empty_final_Line) -> Result<(), NoFontMatch>
  • push_text_range(self, text, range, font_tokens, imply_empty_final_Line) -> Result<(), NoFontMatch>

New pub struct AnalyzedText has pub method:

  • new(text, direction) -> Self

@dhardy dhardy merged commit a2cf015 into master May 31, 2026
5 checks passed
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.

1 participant