pub struct Document { /* private fields */ }Expand description
A markdown document as its editors share it.
Implementations§
Source§impl Document
impl Document
pub fn new(source: &str, cx: &mut Context<'_, Self>) -> Self
Sourcepub fn with_undo_limit(self, limit: usize) -> Self
pub fn with_undo_limit(self, limit: usize) -> Self
How many undo steps to keep; crate::DEFAULT_UNDO_LIMIT until set. A
run of typing coalesces into one step.
Sourcepub fn with_marks(self, marks: Marks) -> Self
pub fn with_marks(self, marks: Marks) -> Self
Read and write this document with marks of its own, rather than the ones
markdown::AppExt::set_marks installed. For an app whose documents do
not all speak the same dialect.
Sourcepub fn with_mode(self, mode: Mode) -> Self
pub fn with_mode(self, mode: Mode) -> Self
Open in Mode::Source rather than on the document — an app whose
document is a markdown file first. Nothing is recorded: this is where
the document starts, not a switch to step back over.
Sourcepub fn source(&self) -> String
pub fn source(&self) -> String
The document as markdown — see crate::Editor::source.
pub fn doc(&self) -> &Doc
Sourcepub fn reload(&mut self, source: &str, cx: &mut Context<'_, Self>)
pub fn reload(&mut self, source: &str, cx: &mut Context<'_, Self>)
Read the document again from source, in the form it is in. The undo
stack and the anchors go with the old text.
Sourcepub fn anchors(&self) -> &[Anchor]
pub fn anchors(&self) -> &[Anchor]
The comment ranges, mapped up to date with the document.
A range that reads Anchor::detached lost the words it pointed at.
It is kept rather than dropped, because whether that means “outdated” or
“resolved” is the app’s question.
Sourcepub fn set_anchors(&mut self, anchors: Vec<Anchor>, cx: &mut Context<'_, Self>)
pub fn set_anchors(&mut self, anchors: Vec<Anchor>, cx: &mut Context<'_, Self>)
Hand over the whole list — the app keeps the threads, this keeps their ranges. One entry point rather than add/remove/update, since the app is already holding the list that decides all three.
Ranges are positions in Self::doc as it stands: the source fence in
Mode::Source, the blocks otherwise.
Sourcepub fn source_with_anchors(&self) -> (String, SourceRanges)
pub fn source_with_anchors(&self) -> (String, SourceRanges)
The markdown to save, and where each anchor’s ends land in it, in byte
offsets, in the order of Self::anchors. A range with an end the
markdown has no place for comes out None.
The string is Self::source but for whitespace a placed end keeps
from being trailing; the ranges index this string, so it is the one to
write beside them.
Sourcepub fn set_source_anchors(
&mut self,
source: &str,
anchors: Vec<SourceAnchor>,
cx: &mut Context<'_, Self>,
)
pub fn set_source_anchors( &mut self, source: &str, anchors: Vec<SourceAnchor>, cx: &mut Context<'_, Self>, )
Self::set_anchors with ranges given in byte offsets into source,
the markdown the document was read from. A range with an end the
document has no place for comes in detached.
Trait Implementations§
impl EventEmitter<DocumentEvent> for Document
Auto Trait Implementations§
impl !RefUnwindSafe for Document
impl !Send for Document
impl !Sync for Document
impl !UnwindSafe for Document
impl Freeze for Document
impl Unpin for Document
impl UnsafeUnpin for Document
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> 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