Skip to main content

Module text_edit

Module text_edit 

Expand description

EditCore — the shared headless text-editing model.

Caret + selection state (byte offsets), the in-progress IME composition, an optional per-character admission filter, and the motion / edit vocabulary every editable surface needs, built on the shared text_selection boundary walkers. Edits come back as byte-space Edit splices the host applies to its mirror (Edit::apply) and its Automerge Text (Edit::splice_automerge, char-addressed). It is deliberately UI-free: no rendering, no CRDT handle.

Every text field uses it: TextInput (and through it every form field, RichTextLine and BlockEditor), the transient query fields of palettes and menus (QueryComposition), NameField, and the app-specific editors. Laid-out geometry — visual/bidi arrow motion, wrapped Up/Down, Home/End of a soft-wrapped row — stays in the widget, which feeds the resolved position back through EditCore::motion_to or EditCore::place_position; the core owns everything logical, which is exactly what unit tests can pin without a GPU.

TypingRun notes when the user last typed, so a word being typed is not checked before it settles.

Structs§

CaretWord
Debounces the word under the caret: it is settled once the same word (same text at the same place) has been under a collapsed caret for SUGGESTION_SETTLE. Typing into the word or moving to another one restarts the wait; moving the caret within the word does not.
CharSplice
An Edit in Automerge’s char offsets: delete removed chars at char at, then insert inserted chars there.
Edit
A splice to apply to the buffer, in byte offsets over the pre-edit text: at..at+removed is replaced by inserted. Edit::apply applies it to a String mirror; Edit::splice_automerge to a char-addressed Automerge Text.
EditCore
The caret + selection model, the IME composition in progress, and the field’s admission filter. Selection offsets are bytes into the bound text (matching text_selection and cosmic-text’s byte-indexed layout).
TypingRun
A burst of typing: every edit touches the run, and a programmatic replacement of the text closes it.

Enums§

Motion
A caret motion. Vertical motion across wrapped lines is the host’s job because it needs laid-out line geometry; Motion::LineUp and Motion::LineDown move across \n-delimited lines only.

Constants§

SUGGESTION_SETTLE
How long the word under the caret must stay the same before a field offers a spelling suggestion for it: a short pause at the end of a word, or the caret coming to rest in a word typed earlier.

Functions§

delete_last_grapheme
Backspace for text typed only at its end (a type-ahead query, a digit entry): remove the last character as a person sees it, never half of a combining sequence or an emoji. Returns whether anything was removed.
word_at_caret
The word the caret is in or just after, as a byte range: letters plus in-word apostrophes, so don't is one word. None between words.

Type Aliases§

CharFilter
A per-character admission rule (for example a spreadsheet cell-reference box that only takes [A-Za-z0-9$:]). Applied to every insertion path: typing, paste, IME preedit and commit, programmatic insertion.