Module marks
Expand description
Inline marks model used by RichTextLine.
A MarkSpan is a half-open byte range [start, end) over a
RichTextLine’s text plus a Mark tag, stored sorted by start.
Multiple marks may cover the same byte range — bold + italic on the same
word produces two MarkSpans, not one fused BoldItalic variant.
Two marks of different kinds may share a range, but two marks of the same
kind never overlap — the mutation helpers (toggle_mark_range) enforce
this by merging touching same-kind spans and removing same-kind spans
fully covered by the toggle range.
Nested markdown (**bold *italic***) is out of scope: the serialiser
emits it and the parser accepts it, but the model treats bold + italic as
independent marks rather than materialising a “bold-italic” variant —
enough for round-trip stability on documents we produce.
Structs§
- Mark
Segment - A contiguous [start, end) segment tagged with the set of marks active
inside it. One
draw_textcall per segment on the render path. - Mark
Span - A byte range + a single
Mark. MultipleMarkSpans with the same kind never overlap (the toggle helpers merge them); different kinds may share a range. - Mention
Colors - How a mention of one participant is painted.
Enums§
- Mark
- One inline mark applied to a byte range of a
RichTextLine. - Toggle
Outcome - Result of
toggle_mark_range: did the toggle add or remove the mark on this range? Returned so the caller can update any pending “next character will be marked” state.
Functions§
- add_
mark_ to_ range - Add a same-kind span covering
rangeand merge any touching / overlapping same-kind spans into a single run. - range_
fully_ covered - True iff every byte in
range(a non-empty sub-range of the line) is covered by at least one same-kind span. Used to decide whether a toggle should add or remove the mark. - remove_
mark_ from_ range - Remove every same-kind coverage from
range. Spans that straddle either edge ofrangeget clipped or split. - segments_
for - Produce the partition. Boundaries: every span’s
startandend, plus 0 andtext_len. The resulting segments together cover[0, text_len). - shift_
after_ edit - Adjust every span’s range by a splice at byte
at, to keep marks aligned after a user edit. Insertion: spans at/afteratshift right, straddling spans extend right. Deletion of[at, at+removed_len): spans entirely inside are dropped, straddling spans are clipped. - toggle_
mark_ range - Apply a toggle of
markoverrange: if fully covered by same-kind spans, remove the coverage (clip/split); otherwise add a new span and merge touching same-kind spans into one contiguous run.
Type Aliases§
- Mention
Paint - The colours a mention of the participant with this id is painted in, supplied by the owning model (it knows who the participant is).
- PageId
- Stable identifier for a page link target.
RichTextLinedoesn’t own page identity — that’s the notes app’s concern — so a UUID is used here; the notes app’sPageIdis itself auuid::Uuid, soMark::Link(PageId)round-trips through the markdown layer.