# RichTextDocument

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/documents/struct-richtextdocument/

**struct** · [`ferroui-controls`](/docs/0.5.0/api/ferroui-controls/) · v0.5.0

```rust
struct RichTextDocument
```

Authoritative structured content shared by read-only and editable text controls.
Its plain string is a derived read cache; every mutation changes the block tree.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L133)

## Members

- [`new`](#function-new)
- [`with_blocks`](#function-with_blocks)
- [`from_text`](#function-from_text)
- [`blocks`](#function-blocks)
- [`revision`](#function-revision)
- [`downgrade`](#function-downgrade)
- [`paragraphs`](#function-paragraphs)
- [`text`](#function-text)
- [`text_length`](#function-text_length)
- [`changed`](#function-changed)
- [`begin_edit`](#function-begin_edit)
- [`snapshot`](#function-snapshot)
- [`restore`](#function-restore)
- [`validate_range`](#function-validate_range)
- [`get_text`](#function-get_text)
- [`slice`](#function-slice)
- [`replace_text`](#function-replace_text)
- [`replace_range`](#function-replace_range)
- [`apply_format`](#function-apply_format)
- [`apply_paragraph_format`](#function-apply_paragraph_format)
- [`character_format_at`](#function-character_format_at)
- [`element_at`](#function-element_at)
- [`create_pointer`](#function-create_pointer)
- [`is_grapheme_boundary`](#function-is_grapheme_boundary)
- [`previous_grapheme`](#function-previous_grapheme)
- [`next_grapheme`](#function-next_grapheme)
- [`previous_word`](#function-previous_word)
- [`next_word`](#function-next_word)

<a id="function-new"></a>

### new

```rust
fn new() -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L311)

<a id="function-with_blocks"></a>

### with_blocks

```rust
fn with_blocks(blocks: BlockCollection) -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L315)

<a id="function-from_text"></a>

### from_text

```rust
fn from_text(text: &str) -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L364)

<a id="function-blocks"></a>

### blocks

```rust
fn blocks(self: &Self) -> BlockCollection
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L372)

<a id="function-revision"></a>

### revision

```rust
fn revision(self: &Self) -> u64
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L375)

<a id="function-downgrade"></a>

### downgrade

```rust
fn downgrade(self: &Self) -> WeakRichTextDocument
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L388)

<a id="function-paragraphs"></a>

### paragraphs

```rust
fn paragraphs(self: &Self) -> Vec<Ref<Paragraph>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L391)

<a id="function-text"></a>

### text

```rust
fn text(self: &Self) -> String
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L400)

<a id="function-text_length"></a>

### text_length

```rust
fn text_length(self: &Self) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L408)

<a id="function-changed"></a>

### changed

```rust
fn changed(self: &Self, handler: impl Fn(&DocumentChangedEventArgs) -> () + 'static) -> Subscription
```

Dropping the returned guard removes the handler; `Subscription::detach` keeps it for the
life of the document.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L430)

<a id="function-begin_edit"></a>

### begin_edit

```rust
fn begin_edit(self: &Self) -> DocumentEditBatch
```

Nested batches publish one revision and one Changed event at the outer end.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L559)

<a id="function-snapshot"></a>

### snapshot

```rust
fn snapshot(self: &Self) -> DocumentSnapshot
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L566)

<a id="function-restore"></a>

### restore

```rust
fn restore(self: &Self, snapshot: &DocumentSnapshot) -> Result<(), DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L574)

<a id="function-validate_range"></a>

### validate_range

```rust
fn validate_range(self: &Self, range: Range<usize>) -> Result<(), DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L578)

<a id="function-get_text"></a>

### get_text

```rust
fn get_text(self: &Self, range: Range<usize>) -> Result<String, DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L582)

<a id="function-slice"></a>

### slice

```rust
fn slice(self: &Self, range: Range<usize>) -> Result<DocumentSnapshot, DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L595)

<a id="function-replace_text"></a>

### replace_text

```rust
fn replace_text(self: &Self, range: Range<usize>, text: &str) -> Result<(), DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L600)

<a id="function-replace_range"></a>

### replace_range

```rust
fn replace_range(self: &Self, range: Range<usize>, fragment: &DocumentSnapshot) -> Result<(), DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L799)

<a id="function-apply_format"></a>

### apply_format

```rust
fn apply_format(self: &Self, range: Range<usize>, format: &CharacterFormat) -> Result<(), DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1004)

<a id="function-apply_paragraph_format"></a>

### apply_paragraph_format

```rust
fn apply_paragraph_format(self: &Self, range: Range<usize>, format: &ParagraphFormat) -> Result<(), DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1070)

<a id="function-character_format_at"></a>

### character_format_at

```rust
fn character_format_at(self: &Self, offset: usize) -> Result<CharacterFormat, DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1124)

<a id="function-element_at"></a>

### element_at

```rust
fn element_at(self: &Self, offset: usize, gravity: TextGravity) -> Option<Ref<TextElement>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1132)

<a id="function-create_pointer"></a>

### create_pointer

```rust
fn create_pointer(self: &Self, offset: usize, gravity: TextGravity) -> Result<TextPointer, DocumentError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1153)

<a id="function-is_grapheme_boundary"></a>

### is_grapheme_boundary

```rust
fn is_grapheme_boundary(self: &Self, offset: usize) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1161)

<a id="function-previous_grapheme"></a>

### previous_grapheme

```rust
fn previous_grapheme(self: &Self, offset: usize) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1166)

<a id="function-next_grapheme"></a>

### next_grapheme

```rust
fn next_grapheme(self: &Self, offset: usize) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1175)

<a id="function-previous_word"></a>

### previous_word

```rust
fn previous_word(self: &Self, offset: usize) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1183)

<a id="function-next_word"></a>

### next_word

```rust
fn next_word(self: &Self, offset: usize) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/rich_text_document.rs#L1197)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `PartialEq`
- `Debug`
- `Default`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
