pub struct MarkdownEditor { /* private fields */ }Expand description
An Obsidian-style live-preview markdown editor. Create with
cx.new(|cx| MarkdownEditor::new(cx)).
The text model is the unit-tested EditorModel (char-index cursor,
anchor selection, coalesced undo); markdown structure comes from the pure
block/inline/layout
passes. Read-only editors render pure preview — selection, copy, and
plain-click links still work.
Implementations§
Source§impl MarkdownEditor
impl MarkdownEditor
pub fn new(cx: &mut Context<'_, Self>) -> Self
Sourcepub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
pub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
Dimmed hint shown while the document is empty and unfocused.
Sourcepub fn read_only(self, read_only: bool) -> Self
pub fn read_only(self, read_only: bool) -> Self
Render pure preview: no caret, no edits, no syntax reveal. Selection, copy, and plain-click link activation still work.
Sourcepub fn font_size(self, size: f32) -> Self
pub fn font_size(self, size: f32) -> Self
Base font size in px (default 15.0). Headings scale from it.
Sourcepub fn style(self, style: MarkdownStyle) -> Self
pub fn style(self, style: MarkdownStyle) -> Self
Per-editor visual overrides (see MarkdownStyle).
Sourcepub fn set_style(&mut self, style: MarkdownStyle, cx: &mut Context<'_, Self>)
pub fn set_style(&mut self, style: MarkdownStyle, cx: &mut Context<'_, Self>)
Replace the style at runtime (theme switches).
Sourcepub fn set_text(&mut self, value: &str, cx: &mut Context<'_, Self>)
pub fn set_text(&mut self, value: &str, cx: &mut Context<'_, Self>)
Replace the document, resetting cursor, selection, and history.
Sourcepub fn focus_handle(&self) -> FocusHandle
pub fn focus_handle(&self) -> FocusHandle
The editor’s focus handle, so a host can focus it on open.
Sourcepub fn model(&self) -> &EditorModel
pub fn model(&self) -> &EditorModel
Read access to the underlying EditorModel — cursor, selection,
lines — for hosts building features over the buffer.
Sourcepub fn edit<R>(
&mut self,
cx: &mut Context<'_, Self>,
f: impl FnOnce(&mut EditorModel) -> R,
) -> R
pub fn edit<R>( &mut self, cx: &mut Context<'_, Self>, f: impl FnOnce(&mut EditorModel) -> R, ) -> R
Mutate the EditorModel directly. Emits
MarkdownEditorEvent::Change when the text changed, keeps the
caret visible, and repaints.
Sourcepub fn bind(
entity: &Entity<MarkdownEditor>,
signal: &Signal<String>,
cx: &mut App,
)
pub fn bind( entity: &Entity<MarkdownEditor>, signal: &Signal<String>, cx: &mut App, )
Two-way bind this editor’s text to a Signal<String>. The signal is
the source of truth; equality guards on both directions prevent
update loops.
Sourcepub fn toggle_task(&mut self, line: usize, cx: &mut Context<'_, Self>) -> bool
pub fn toggle_task(&mut self, line: usize, cx: &mut Context<'_, Self>) -> bool
Toggle the checkbox on line if it is a task item, preserving the
cursor. Returns whether the line was a task.
Trait Implementations§
impl EventEmitter<MarkdownEditorEvent> for MarkdownEditor
Source§impl Render for MarkdownEditor
impl Render for MarkdownEditor
Auto Trait Implementations§
impl !RefUnwindSafe for MarkdownEditor
impl !Send for MarkdownEditor
impl !Sync for MarkdownEditor
impl !UnwindSafe for MarkdownEditor
impl Freeze for MarkdownEditor
impl Unpin for MarkdownEditor
impl UnsafeUnpin for MarkdownEditor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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