RichEditTextRange
struct · ferroui-controls · v0.5.0
struct RichEditTextRange
A live, independent range. Explicit plain range SetText tracks its endpoints
as a pair from the accepted operation span. Other mutation origins retain the
document's ordinary TextPointer affinity policy.
RangeGravity independently selects formatting at a collapsed boundary.
Cloning shares the range object; get_clone creates independent endpoints.
Members
set_text_via_streamget_text_via_streamchange_casecharactercharacter_scalarset_characterset_character_scalardeletecan_paste_from_clipboard_asynccopy_to_clipboard_asynccut_to_clipboard_asyncpaste_from_clipboard_asyncgravityset_gravityset_gravity_valuedocumentstart_positionend_positionrangelengthstory_lengthis_degeneratetextget_textsnapshotget_rectanglesget_cloneformatted_textset_formatted_textset_start_positionset_end_positionset_rangecollapseselectin_rangeis_equalin_storymatch_selectionget_character_utf32set_textset_text_with_optionsset_snapshotset_character_formatset_paragraph_formatcharacter_formatparagraph_formatexpandstart_ofend_ofget_indexset_indexmove_bymove_startmove_endfindfind_textfind_text_with_length
set_text_via_stream
fn set_text_via_stream(self: &Self, options: TextSetOptions, reader: &mut dyn Read, stream: TextStreamOptions) -> Result<(), TextOperationError>
Replaces this live range from the reader's current position. The complete payload is validated first; the editor's independent selection is rebased and the replacement becomes one undoable operation.
get_text_via_stream
fn get_text_via_stream(self: &Self, options: TextGetOptions, writer: &mut dyn Write, stream: TextStreamOptions) -> Result<(), TextOperationError>
Writes this range without moving its endpoints or changing editor history. The stream's position, lifetime, and completion/flush policy belong to the caller, as in FerroUI's other Read/Write-based storage APIs.
change_case
fn change_case(self: &Self, value: LetterCase) -> Result<bool, EditError>
Changes the selected letters without flattening inline formatting, links, paragraph properties, soft breaks or embedded controls. Unicode expansions rebase the independent directed selection; the edit is one undo unit.
The complete selected string supplies contextual lowercase rules, even
across differently formatted runs. A degenerate or unchanged range returns
false without touching composition, revision, typing format or history.
An expansion exceeding MaxLength fails before replacing content rather
than truncating the transformed text. Locale-specific native casing remains
separate from this portable Unicode default-casing operation.
character
fn character(self: &Self) -> u16
The UTF-16 code unit at StartPosition, including the leading surrogate of a supplementary character. A caret at the end of this model story returns zero; the native synthetic terminal paragraph marker is not exposed.
character_scalar
fn character_scalar(self: &Self) -> Option<char>
Returns the complete Unicode scalar at StartPosition, independently of whether this range is degenerate. None means the end of the model story.
set_character
fn set_character(self: &Self, value: u16) -> Result<bool, EditError>
Replaces the first UTF-16 code unit without moving the range's start.
Isolated surrogate input and replacement of half an existing pair are
rejected before changing content, composition or history. Use
set_character_scalar for a complete scalar.
set_character_scalar
fn set_character_scalar(self: &Self, value: char) -> Result<bool, EditError>
Replaces the complete scalar at StartPosition. This Rust extension to the native Char16 property supports supplementary characters without exposing invalid intermediate UTF-16. It retains the replaced character's format, rebases the independent directed selection, and creates one undo unit.
delete
fn delete(self: &Self, unit: TextRangeUnit, count: i32) -> Result<usize, EditError>
Deletes this range and, for a nonzero count, additional logical units in the requested direction. Removing a nonempty range counts as one unit; count zero removes only that range. The return value is a nonnegative count of removed units, using usize so even i32::MIN has no abs overflow.
A nonempty range is removed before resolving the remaining units: joining its surrounding text can change word, paragraph and shaped line boundaries. All changes use one undo transaction and preserve the independent editor selection. Unavailable layout-dependent units fail explicitly.
can_paste_from_clipboard_async
fn can_paste_from_clipboard_async(self: &Self, clipboard: Rc<dyn IClipboard>, format: RichTextPasteFormat) -> LocalBoxFuture<Result<bool, ClipboardError>>
Queries the exact requested format policy. Read-only targets return false without accessing the clipboard. Availability does not validate a payload that may be supplied lazily, or guarantee a subsequent platform read.
copy_to_clipboard_async
fn copy_to_clipboard_async(self: &Self, clipboard: Rc<dyn IClipboard>) -> LocalBoxFuture<Result<(), ClipboardError>>
Copies the captured range as exact in-process content, representable RTF, and plain text. Copy never changes the editor's selection, composition or undo history; a degenerate range leaves the clipboard unchanged.
The immutable fragment is captured when this method is called. The
clipboard owns the outgoing transfer once set_data_async is invoked.
cut_to_clipboard_async
fn cut_to_clipboard_async(self: &Self, clipboard: Rc<dyn IClipboard>) -> LocalBoxFuture<Result<(), ClipboardError>>
Copies this independent range, then deletes precisely that captured target after the clipboard write succeeds. Later edits, range changes, selection requests, or IME sessions cancel the pending deletion.
On its first poll, a nonempty cut follows the editor's ordinary edit policy and cancels an existing preview before capturing committed text. A failed clipboard write leaves that committed text and history intact; it does not restart the canceled preview. An empty cut has no side effects.
paste_from_clipboard_async
fn paste_from_clipboard_async(self: &Self, clipboard: Rc<dyn IClipboard>, format: RichTextPasteFormat) -> LocalBoxFuture<Result<(), ClipboardError>>
Replaces this independent range using exactly the requested clipboard format policy. A successful edit preserves and rebases the editor's directed selection and creates one undo unit.
Missing/empty data, invalid payloads, platform errors and stale requests do not cancel IME or change the target. After a valid payload arrives, an original preview is canceled and the live committed endpoints are read again. Plain text inherits insertion formatting; rich fragments keep their assigned formatting and structure.
gravity
fn gravity(self: &Self) -> RangeGravity
Reads this independent range's accepted formatting affinity.
set_gravity
fn set_gravity(self: &Self, gravity: RangeGravity)
Changes range metadata without changing text, selection, composition or undo/redo. Rust Clone shares this setting; get_clone() starts with UIBehavior. Endpoint setters retain it. Successful text undo leaves the current mode.
A real mode change retires pending asynchronous range operations, even when a later setter returns to the original mode. Outward is accepted as UIBehavior, matching the measured native setter readback.
set_gravity_value
fn set_gravity_value(self: &Self, value: i32) -> Result<(), EditError>
Checked numeric boundary for native/serialized values. Invalid values leave all state untouched; the typed setter cannot receive them.
document
fn document(self: &Self) -> RichTextDocument
start_position
fn start_position(self: &Self) -> usize
end_position
fn end_position(self: &Self) -> usize
range
fn range(self: &Self) -> Range<usize>
length
fn length(self: &Self) -> usize
story_length
fn story_length(self: &Self) -> usize
Length of the single story in FerroUI's UTF-16 model coordinates. As with the range endpoints, this excludes the synthetic terminal mark emitted by complete-document text retrieval.
is_degenerate
fn is_degenerate(self: &Self) -> bool
text
fn text(self: &Self) -> Result<String, EditError>
get_text
fn get_text(self: &Self, options: TextGetOptions) -> Result<String, TextOperationError>
snapshot
fn snapshot(self: &Self) -> Result<DocumentSnapshot, EditError>
get_rectangles
fn get_rectangles(self: &Self, view: &RichTextBlock) -> Result<Vec<Rect>, EditError>
Returns one rectangle for each visual fragment, including bidirectional and wrapped text.
get_clone
fn get_clone(self: &Self) -> Result<Self, EditError>
formatted_text
fn formatted_text(self: &Self) -> Result<Self, EditError>
set_formatted_text
fn set_formatted_text(self: &Self, value: &Self) -> Result<(), EditError>
set_start_position
fn set_start_position(self: &Self, position: usize) -> Result<(), EditError>
set_end_position
fn set_end_position(self: &Self, position: usize) -> Result<(), EditError>
set_range
fn set_range(self: &Self, start: usize, end: usize) -> Result<(), EditError>
collapse
fn collapse(self: &Self, to_start: bool) -> Result<(), EditError>
select
fn select(self: &Self) -> Result<(), EditError>
in_range
fn in_range(self: &Self, other: &Self) -> bool
is_equal
fn is_equal(self: &Self, other: &Self) -> bool
in_story
fn in_story(self: &Self, other: &Self) -> bool
match_selection
fn match_selection(self: &Self) -> Result<(), EditError>
get_character_utf32
fn get_character_utf32(self: &Self, offset: i32) -> u32
Decodes the scalar at a signed UTF-16 offset from the range's end. Either half of a surrogate pair returns its scalar; outside the story returns zero.
set_text
fn set_text(self: &Self, text: &str) -> Result<(), EditError>
Replaces the range while preserving and rebasing the editor's independent selection. The change, formatting, and selection are one undoable transaction.
set_text_with_options
fn set_text_with_options(self: &Self, options: TextSetOptions, text: &str) -> Result<(), TextOperationError>
set_snapshot
fn set_snapshot(self: &Self, snapshot: &DocumentSnapshot) -> Result<(), EditError>
set_character_format
fn set_character_format(self: &Self, format: &CharacterFormat) -> Result<(), EditError>
set_paragraph_format
fn set_paragraph_format(self: &Self, format: &ParagraphFormat) -> Result<(), EditError>
character_format
fn character_format(self: &Self) -> Result<TextFormatValue<CharacterFormat>, EditError>
Queries effective formats at run boundaries, so a long uniform run is inspected once.
paragraph_format
fn paragraph_format(self: &Self) -> Result<TextFormatValue<ParagraphFormat>, EditError>
expand
fn expand(self: &Self, unit: TextRangeUnit) -> Result<usize, EditError>
Expands to the smallest whole TOM units containing the range. Whole-word search retains independent Unicode boundaries and excludes trailing blanks.
start_of
fn start_of(self: &Self, unit: TextRangeUnit, extend: bool) -> Result<isize, EditError>
Moves to the beginning of the first overlapping unit. Extension changes only the start; otherwise the range collapses. The signed UTF-16 displacement is always nonpositive, including zero when already on a unit boundary.
end_of
fn end_of(self: &Self, unit: TextRangeUnit, extend: bool) -> Result<isize, EditError>
Moves to the end of the last overlapping unit. A collapse contributes one to the returned UTF-16 displacement, matching the native EndOf contract. The synthetic final-CR case is outside FerroUI's range coordinates.
get_index
fn get_index(self: &Self, unit: TextRangeUnit) -> Result<usize, EditError>
Gets the one-based story index at StartPosition. At the end of a story it reports the total unit count; a unit absent from empty content has index zero.
set_index
fn set_index(self: &Self, unit: TextRangeUnit, index: i32, extend: bool) -> Result<(), EditError>
Relocates to a whole unit (extend) or its starting insertion point. Positive indices count from one; negative indices count back from the last unit. Zero and out-of-range indices fail without changing the live range.
move_by
fn move_by(self: &Self, unit: TextRangeUnit, count: i32) -> Result<i32, EditError>
A non-degenerate range first collapses toward the movement direction and reaches the nearest unit boundary. That collapse counts as the first unit.
move_start
fn move_start(self: &Self, unit: TextRangeUnit, count: i32) -> Result<i32, EditError>
move_end
fn move_end(self: &Self, unit: TextRangeUnit, count: i32) -> Result<i32, EditError>
find
fn find(self: &Self, text: &str, options: TextFindOptions) -> Result<Option<Self>, EditError>
Searches this range. Case-insensitive matching uses Unicode lowercase mappings; UTF-16 offsets remain exact even when a character maps to several lowercase scalars.
find_text
fn find_text(self: &Self, text: &str, options: TextFindOptions) -> Result<bool, EditError>
find_text_with_length
fn find_text_with_length(self: &Self, text: &str, scan_length: i32, options: FindOptions) -> Result<usize, EditError>
Native bounded search: positive lengths start at StartPosition, negative lengths search backward from EndPosition. Zero searches the existing range, or the remaining story for a caret. A repeat skips the range already found.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedClassDefaultsErasedDestructorIntoEitherClone
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.