Skip to main content

RichDoc

Struct RichDoc 

Source
pub struct RichDoc {
    pub font: String,
    pub size: u16,
    /* private fields */
}
Expand description

the document of ui.richtext (see the module header)

Fields§

§font: String

the document’s font family (“”: the UI font)

§size: u16

the document’s size in tenths of a point (0: 11 pt)

Implementations§

Source§

impl RichDoc

Source

pub fn new() -> RichDoc

one empty paragraph

Source

pub fn from_paras(paras: Vec<Para>) -> RichDoc

paragraphs (an empty list: one empty paragraph); the caret at the start

Source

pub fn from_plain(s: &str) -> RichDoc

unformatted text: a paragraph per line

Source

pub fn paras(&self) -> &[Para]

the content (no history)

Source

pub fn para(&self, i: usize) -> &Para

paragraph i (clamped to the last one)

Source

pub fn para_count(&self) -> usize

the number of paragraphs (at least 1)

Source

pub fn revision(&self) -> u64

counts the changes of the content (edits, undo, redo; not the selection)

Source

pub fn selection(&self) -> TextSel

the selection (the caret: anchor == caret)

Source

pub fn set_selection(&mut self, sel: TextSel)

move the selection (clamped to the text, not undoable)

Source

pub fn clamp(&self, p: TextPos) -> TextPos

p inside the document, on a character boundary

Source

pub fn end(&self) -> TextPos

the end of the document

Source

pub fn text(&self) -> String

the text: the paragraphs joined by ‘\n’ (no list markers)

Source

pub fn flat(&self, p: TextPos) -> usize

the byte offset of p in text()

Source

pub fn unflat(&self, f: usize) -> TextPos

the position of byte offset f of text()

Source

pub fn text_range(&self, a: TextPos, b: TextPos) -> String

the text between a and b (paragraphs joined by ‘\n’)

Source

pub fn paras_range(&self, a: TextPos, b: TextPos) -> Vec<Para>

the paragraphs between a and b (the first and the last cut there), with attributes

Source

pub fn selected_text(&self) -> String

the selected text

Source

pub fn selected_paras(&self) -> Vec<Para>

the selected paragraphs (a fragment for the clipboard)

Source

pub fn current_para(&self) -> &Para

the paragraph with the caret

Source

pub fn current_fmt(&self) -> Fmt

the format typing takes now (a format chosen without a selection, else the text’s at the caret); with a selection: its first character’s, the flags all of it has

the link target at p (None: no link there)

Source

pub fn can_undo(&self) -> bool

there is a step to undo

Source

pub fn can_redo(&self) -> bool

there is a step to redo

Source

pub fn undo_label(&self) -> Option<&str>

the label of the step undo takes back (“Fett”, “Schreiben” …)

Source

pub fn redo_label(&self) -> Option<&str>

the label of the step redo does again

Source

pub fn undo(&mut self) -> bool

take the last step back -> false: nothing to undo

Source

pub fn redo(&mut self) -> bool

do the last undone step again -> false: nothing to redo

Source

pub fn is_dirty(&self) -> bool

the content differs from the state of the last mark_saved

Source

pub fn mark_saved(&mut self)

the content is saved now (is_dirty false until the next change)

Source

pub fn clear_history(&mut self)

forget the undo steps

Source

pub fn group_begin(&mut self, label: &str)

the next edits are one undo step (until group_end)

Source

pub fn group_end(&mut self)

close the step of group_begin

Source

pub fn insert_text(&mut self, s: &str) -> bool

replace the selection by text (a paragraph per line) in the current format

Source

pub fn insert_paras(&mut self, frag: &[Para]) -> bool

replace the selection by paragraphs (a paste): several keep their attributes, one is inserted into the paragraph at the caret

Source

pub fn delete_selection(&mut self) -> bool

remove the selection

Source

pub fn delete(&mut self, a: TextPos, b: TextPos) -> bool

remove a..b (the caret goes to a)

Source

pub fn split(&mut self) -> bool

Enter: split the paragraph at the caret (the selection is replaced). In an empty list item the list ends instead (a nested one moves out a level); after a heading the new paragraph is body text.

Source

pub fn toggle(&mut self, flag: u8) -> bool

RF_BOLD / RF_ITALIC / RF_UNDER / RF_STRIKE on (when not all of the selection has it) or off

Source

pub fn set_flags(&mut self, flags: u8, on: bool) -> bool

set (on) or clear flags

Source

pub fn set_color(&mut self, argb: u32) -> bool

the text colour (0: the theme’s)

Source

pub fn set_bg(&mut self, argb: u32) -> bool

the highlight colour (0: none)

Source

pub fn set_size(&mut self, tenths: u16) -> bool

the size in tenths of a point (0: the document’s)

Source

pub fn set_font(&mut self, family: &str) -> bool

the font family (“”: the document’s)

a link on the selection (without one: on the link at the caret); “” removes it. A collapsed caret outside a link inserts the url as linked text.

Source

pub fn clear_format(&mut self) -> bool

back to the default format (links stay)

Source

pub fn set_align(&mut self, align: u8) -> bool

RA_* for the selected paragraphs

Source

pub fn toggle_list(&mut self, kind: u8) -> bool

LS_BULLET / LS_NUMBER: the selected paragraphs become such list items, or plain paragraphs when all of them already are

Source

pub fn set_list(&mut self, kind: u8) -> bool

LS_* without toggling

Source

pub fn indent(&mut self, delta: i32) -> bool

one level deeper (delta 1) or out (-1), 0..LEVEL_MAX

Source

pub fn set_style(&mut self, style: u8) -> bool

PS_* for the selected paragraphs

Source

pub fn set_paras(&mut self, paras: Vec<Para>) -> bool

replace the whole content (one undo step)

Source

pub fn to_json(&self) -> String

the document as JSON (see the module header)

Source

pub fn from_json(s: &str) -> Option<RichDoc>

a document from to_json’s JSON (None: not such a document)

Source

pub fn to_plain(&self) -> String

the text with list markers (“• “, “1. “) and two blanks of indent per level

Source§

impl RichDoc

Source

pub fn to_html(&self) -> String

the document as an HTML fragment (see rich_html.rs)

Source

pub fn from_html(s: &str) -> RichDoc

a document from HTML (see rich_html.rs); a fragment of a richtext’s clipboard is taken exactly

Trait Implementations§

Source§

impl Clone for RichDoc

Source§

fn clone(&self) -> RichDoc

the content and the selection (not the undo history)

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for RichDoc

Source§

fn default() -> RichDoc

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.