pub struct RenderedText { /* private fields */ }Expand description
A snapshot of the text a TextViewState renders,
as of one parse of its content.
Offsets into it are UTF-8 byte offsets. It is the string plain copy
produces: hello **world** renders as hello world, escapes are
resolved, and heading markers and list markers are left out. Blocks end
with a newline and table cells are joined with a space; those separators
belong to no block, so no highlight paints them.
Two snapshots are equal when they come from the same view and the same
parse. Comparing the current rendered_text with the one last searched
tells an observer of the view whether its content changed, so setting
highlights, which notifies the view too, does not start another search.
The text itself is only built when it is first read, from the parsed
document the snapshot holds on to, so drop a snapshot that is no longer
needed rather than keeping it past many changes.
Implementations§
Source§impl RenderedText
impl RenderedText
Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
The source this text was rendered from, whose byte ranges
range_for_source takes.
It comes from the same parse as the text, so it trails the text last
given to the view until that text’s parse lands. Before converting a
range, check that it indexes this source: while text is streamed in,
this source is a prefix of the text the application holds, and after
set_text it may be different text.
Sourcepub fn range_for_source(&self, source: Range<usize>) -> Option<Range<usize>>
pub fn range_for_source(&self, source: Range<usize>) -> Option<Range<usize>>
The range of this text rendered from source, a UTF-8 byte range of
Self::source.
This converts a range of the Markdown source, such as one
selected_source_range returned or one an application stored with
its own data, into the range a RangeHighlight takes. A character is
rendered from source when any of the source it was rendered from lies
in it: all of & for &, the \ and the * of \*, the whole
source of an inline object for its text. Source that renders nothing,
such as emphasis delimiters, heading and list markers, code fences,
table pipes and link destinations, adds nothing, so **bold** and
bold give the same range.
The result is the smallest range holding every character rendered from
source. When source spans blocks, it also holds the separators
between them, which a highlight leaves unpainted. Text the parser
recorded no source position for, such as the text of inline HTML, is
only included when it lies between characters that are.
Converting the source range a selection of this text reports gives the selected range back, widened only to whole characters where several share their source, like the text of an inline object. The separators between blocks are rendered from no source, so one at either end of the selection is left out: Select All gives back everything but the line break after the last block.
Returns None when source is empty, reversed, out of bounds, or not on
a character boundary, or when nothing is rendered from it. HTML views
record no source positions, so they always return None.
Trait Implementations§
Source§impl Clone for RenderedText
impl Clone for RenderedText
Source§fn clone(&self) -> RenderedText
fn clone(&self) -> RenderedText
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RenderedText
impl Debug for RenderedText
impl Eq for RenderedText
Auto Trait Implementations§
impl !RefUnwindSafe for RenderedText
impl !UnwindSafe for RenderedText
impl Freeze for RenderedText
impl Send for RenderedText
impl Sync for RenderedText
impl Unpin for RenderedText
impl UnsafeUnpin for RenderedText
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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