package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Text_buffer/index.html
Module Mosaic_ui.Text_bufferSource
Styled text storage with per-character styles and highlight overlays.
Styled text storage with per-character styles and highlight overlays.
A text buffer stores content as a sequence of styled spans. It tracks logical line boundaries and per-line display widths. Highlights (see Highlight) provide priority-based style overlays for selection and syntax highlighting.
Consumers typically wrap a buffer in a Text_surface.t for rendering.
A mutable styled text buffer.
Spans
A contiguous run of text with a single visual style.
Highlights
Construction
val create :
?default_style:Ansi.Style.t ->
?width_method:Glyph.width_method ->
?tab_width:int ->
unit ->
tcreate () is an empty buffer with:
default_style: style applied to plain text set viaset_textandappend. Defaults toAnsi.Style.default.width_method: grapheme width computation method. Defaults to`Unicode.tab_width: tab stop width, clamped to>= 1. Defaults to2.
Content
set_text t s replaces content with plain text s styled with default_style. Invalidates cached metrics.
set_styled_text t spans replaces content with pre-styled spans. Invalidates cached metrics.
append t s appends plain text s styled with default_style. Invalidates cached metrics.
append_styled t spans appends pre-styled spans to existing content. Invalidates cached metrics.
plain_text t is the concatenation of all span texts. Cached; recomputed on content change.
Default style
set_default_style t s changes the default style. Does not re-style existing content.
Line information
line_count t is the number of logical lines (delimited by line breaks). Cached; recomputed on content change.
line_width t n is the display width of logical line n. Returns 0 if n is out of range. Cached; recomputed on content change.
max_line_width t is the display width of the widest logical line. Cached; recomputed on content change.
line_spans t n is the styled spans for logical line n. Uses cached line boundaries to avoid rescanning. Returns [] if n is out of range.
text_in_range t ~start ~len is the plain text for grapheme offsets from start (inclusive) to start + len (exclusive). If start + len exceeds grapheme_count, the result extends to the end of the buffer. Returns "" if start is out of bounds or len <= 0.
Highlight operations
add_highlight t h adds a highlight overlay.
remove_highlights_by_ref t ref_id removes all highlights whose Highlight.ref_id equals ref_id.
highlights_in_range t ~start ~len is the highlights intersecting grapheme offsets from start (inclusive) to start + len (exclusive), sorted by ascending Highlight.priority.
Tab width
set_tab_width t w changes the tab stop width. w is clamped to >= 1. Invalidates cached line info if the value changes.
Width method
width_method t is the grapheme width computation method.
set_width_method t m changes the width method. Invalidates cached line info if m differs from the current value.
Versioning
version t is a monotonically increasing counter incremented whenever content, tab width, or width method changes. Useful for cache invalidation in consumers (e.g. Text_surface).