Expand description
Incremental Knuth-Plass line-break optimizer.
Wraps the existing wrap_optimal DP algorithm with paragraph-level
caching and dirty-region tracking, so only edited/resized paragraphs are
recomputed during reflow.
§Incrementality model
A document is a sequence of paragraphs separated by hard line breaks (\n).
The Knuth-Plass DP runs independently per paragraph, so:
- A text edit affects at most one paragraph (unless it inserts/removes
\n). - A width change invalidates all paragraphs.
- Cached solutions are keyed by
(text_hash, width)for staleness detection.
For very long documents, only dirty paragraphs are re-broken, providing bounded latency proportional to the edited paragraph’s length rather than the total document length.
§Usage
use ftui_text::incremental_break::IncrementalBreaker;
use ftui_text::wrap::ParagraphObjective;
let mut breaker = IncrementalBreaker::new(80, ParagraphObjective::terminal());
let result = breaker.reflow("Hello world. This is a test paragraph.");
assert!(!result.lines.is_empty());Structs§
- Breaker
Snapshot - Diagnostic snapshot of the incremental breaker state.
- Edit
Event - Describes a text edit for incremental reflow.
- Incremental
Breaker - Incremental Knuth-Plass line-break optimizer with paragraph-level caching.
- Reflow
Result - Result of an incremental reflow operation.