Skip to main content

EditorState

Struct EditorState 

Source
pub struct EditorState { /* private fields */ }
Expand description

The editor state. Keep one per editor in your application.

Implementations§

Source§

impl EditorState

Source

pub fn new() -> Self

An empty document.

Source

pub fn with_markdown(markdown_text: &str) -> Self

A document parsed from CommonMark (with the GFM extensions strikethrough, task lists and tables; see Self::features).

Source

pub fn style(self, style: EditorStyle) -> Self

Builder: sets the style.

Source

pub fn paper(self, paper: Paper) -> Self

Builder: sets the paper.

Source

pub fn zoom_settings(self, settings: ZoomSettings) -> Self

Builder: sets the zoom settings.

Source

pub fn zoom(self, zoom: f32) -> Self

Builder: sets the initial zoom.

Source

pub fn tab_width(self, spaces: usize) -> Self

Builder: number of spaces the Tab key inserts (0 = Tab not handled).

Source

pub fn highlighter(self, highlighter: impl CodeHighlighter) -> Self

Builder: installs a code highlighting plugin.

Source

pub fn features(self, features: Features) -> Self

Builder: enables or disables optional Markdown features. The document is read again with the new features.

Source

pub fn language(self, language: Language) -> Self

Builder: sets the language of the toolbar, link bar and status bar.

Source

pub fn block_renderer(self, renderer: impl BlockRenderer) -> Self

Builder: adds a renderer for fenced code blocks of some languages. Call it once per renderer; the first one listing a language wins.

Source

pub fn images(self, settings: ImageSettings) -> Self

Builder: what happens with pasted, dropped and inserted images.

Source

pub fn image_base(self, folder: impl Into<PathBuf>) -> Self

Builder: folder for relative image URLs (desktop display).

Source

pub fn image_loader( self, loader: impl Fn(&str) -> Option<Vec<u8>> + Send + Sync + 'static, ) -> Self

Builder: loads image bytes for display by URL.

Source

pub fn mode(self, mode: Mode) -> Self

Builder: sets the mode.

Source

pub fn markdown(&self) -> String

The document as Markdown, without image placeholders and with full data: URLs. Builds the whole text: call it on changes, not in view.

Source

pub fn plain_text(&self) -> String

The document as plain text.

Source

pub fn selected_text(&self) -> Option<String>

The selected text, if any.

Source

pub fn word_count(&self) -> usize

Source

pub fn current_mode(&self) -> Mode

Source

pub fn current_style(&self) -> &EditorStyle

Source

pub fn current_paper(&self) -> &Paper

Source

pub fn current_zoom(&self) -> f32

Current zoom factor (1.0 = 100 %).

Source

pub fn current_zoom_settings(&self) -> &ZoomSettings

Source

pub fn current_tab_width(&self) -> usize

Spaces per Tab (0 = Tab not handled).

Source

pub fn current_image_settings(&self) -> &ImageSettings

Source

pub fn pending_images(&self) -> usize

Images handed to the application and not answered yet.

Source

pub fn has_highlighter(&self) -> bool

Source

pub fn current_features(&self) -> Features

Source

pub fn current_language(&self) -> Language

Source

pub fn rendered_languages(&self) -> Vec<String>

Languages drawn by block renderers.

Source

pub fn code_languages(&self) -> Vec<String>

Languages offered for code blocks: from the highlighter (or a common list) and the block renderers.

Source

pub fn task_progress(&self) -> (usize, usize)

(checked, total) task list items.

Source

pub fn page_count(&self) -> usize

Number of pages (1 in full-width mode).

Source

pub fn current_page(&self) -> usize

Page (1-based) that contains the caret.

Source

pub fn is_focused(&self) -> bool

Source

pub fn is_dirty(&self) -> bool

true when the content changed since the last load or save.

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn formatting(&self) -> Formatting

Formatting at the caret (or at the start of the selection).

Source

pub fn set_markdown(&mut self, markdown_text: &str)

Replaces the whole document. Clears history, pending images and the dirty flag.

Source

pub fn mark_saved(&mut self)

Clears the dirty flag (call after saving).

Source

pub fn set_style(&mut self, style: EditorStyle)

Source

pub fn set_paper(&mut self, paper: Paper)

Source

pub fn set_zoom_settings(&mut self, settings: ZoomSettings)

Source

pub fn set_zoom(&mut self, zoom: f32)

Sets the zoom factor (1.0 = 100 %), also when zoom is disabled.

Source

pub fn set_tab_width(&mut self, spaces: usize)

Spaces per Tab; 0 leaves Tab to the application.

Source

pub fn set_highlighter(&mut self, highlighter: Option<Arc<dyn CodeHighlighter>>)

Source

pub fn set_language(&mut self, language: Language)

Sets the language of the toolbar, link bar and status bar. The document is not changed.

Source

pub fn set_features(&mut self, features: Features)

Enables or disables optional Markdown features. In WYSIWYG mode the document is read again, as if it had been loaded with the new features; the undo history starts again.

Source

pub fn set_block_renderers(&mut self, renderers: Vec<Arc<dyn BlockRenderer>>)

Replaces the block renderers. The first renderer listing a language draws it.

Source

pub fn set_image_settings(&mut self, settings: ImageSettings)

Source

pub fn set_image_base(&mut self, folder: Option<PathBuf>)

Source

pub fn set_image_loader(&mut self, loader: Option<ImageLoader>)

Source

pub fn reload_images(&mut self)

Forgets loaded images and loads them again.

Source

pub fn set_mode(&mut self, mode: Mode)

Switches between WYSIWYG and source mode. The undo history starts again after a switch.

Source

pub fn execute(&mut self, command: Command) -> Output

Runs a command and reports what happened.

Source

pub fn update(&mut self, action: Action) -> Output

Handles an Action produced by the widget.

Source

pub fn subscription(&self) -> Subscription<Action>

Caret blinking and dropped image files: state.subscription().map(Message::Editor).

Trait Implementations§

Source§

impl Default for EditorState

Source§

fn default() -> Self

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<State, Message> IntoBoot<State, Message> for State

Source§

fn into_boot(self) -> (State, Task<Message>)

Turns some type into the initial state of some Application.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeClone for T

Source§

impl<T> MaybeDebug for T

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more