pub struct SourceText { /* private fields */ }Expand description
A source text and what render_source reads off it every frame: its
lines, a hash of each, and its highlight spans.
SourceText::new walks and highlights the whole text.
SourceText::edit redoes only the lines an edit touched and shifts the
spans around it; the SpanJob it answers highlights the new text in full,
on any thread, for SourceText::set_spans. SourceText::rehighlight
answers one when the installed highlighter has changed.
Implementations§
Source§impl SourceText
impl SourceText
pub fn new(code: impl Into<Arc<str>>, cx: &App) -> Self
pub fn text(&self) -> &str
Sourcepub fn line_of(&self, offset: usize) -> usize
pub fn line_of(&self, offset: usize) -> usize
The line holding byte offset; past the end, the last line.
Sourcepub fn spans(&self) -> Option<&[(Range<usize>, HighlightKind)]>
pub fn spans(&self) -> Option<&[(Range<usize>, HighlightKind)]>
The highlight spans, in bytes and in order. Between an Self::edit
and the Self::set_spans that follows it, the spans from before the
edit, shifted past it, and none over the bytes it replaced.
Sourcepub fn edit(&mut self, code: &str, cx: &App) -> Option<SpanJob>
pub fn edit(&mut self, code: &str, cx: &App) -> Option<SpanJob>
Make the text code. The change is taken to be the one run of bytes
between the longest prefix and suffix the two texts share. None when
the text is unchanged.
Sourcepub fn rehighlight(&mut self, cx: &App) -> Option<SpanJob>
pub fn rehighlight(&mut self, cx: &App) -> Option<SpanJob>
Highlight the text again if the installed highlighter has changed since it was last highlighted. The spans stand until the job’s land.
Auto Trait Implementations§
impl !Freeze for SourceText
impl !RefUnwindSafe for SourceText
impl !Send for SourceText
impl !Sync for SourceText
impl Forget for SourceText
impl Move for SourceText
impl Unpin for SourceText
impl UnsafeUnpin for SourceText
impl UnwindSafe for SourceText
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