pub struct TextViewState { /* private fields */ }Expand description
The state of a TextView.
Implementations§
Source§impl TextViewState
impl TextViewState
Sourcepub fn markdown(text: &str, cx: &mut Context<'_, Self>) -> Self
pub fn markdown(text: &str, cx: &mut Context<'_, Self>) -> Self
Create a Markdown TextViewState.
Sourcepub fn selectable(self, selectable: bool) -> Self
pub fn selectable(self, selectable: bool) -> Self
Set whether the text is selectable, default false.
Sourcepub fn set_selectable(&mut self, selectable: bool, cx: &mut Context<'_, Self>)
pub fn set_selectable(&mut self, selectable: bool, cx: &mut Context<'_, Self>)
Set whether the text is selectable, default false.
Sourcepub fn selection_format(self, selection_format: SelectionFormat) -> Self
pub fn selection_format(self, selection_format: SelectionFormat) -> Self
Set the SelectionFormat, default is SelectionFormat::Plain.
Sourcepub fn set_selection_format(
&mut self,
selection_format: SelectionFormat,
cx: &mut Context<'_, Self>,
)
pub fn set_selection_format( &mut self, selection_format: SelectionFormat, cx: &mut Context<'_, Self>, )
Set the SelectionFormat, default is SelectionFormat::Plain.
Sourcepub fn scrollable(self, scrollable: bool) -> Self
pub fn scrollable(self, scrollable: bool) -> Self
Set whether the text view scrolls internally, default false.
Sourcepub fn set_scrollable(&mut self, scrollable: bool, cx: &mut Context<'_, Self>)
pub fn set_scrollable(&mut self, scrollable: bool, cx: &mut Context<'_, Self>)
Set whether the text view scrolls internally, default false.
Sourcepub fn is_clamped(&self) -> bool
pub fn is_clamped(&self) -> bool
Whether the last painted frame clipped content because of
TextView::max_lines.
Sourcepub fn set_text(&mut self, text: &str, cx: &mut Context<'_, Self>)
pub fn set_text(&mut self, text: &str, cx: &mut Context<'_, Self>)
Set the text content.
With a streamed fade-in enabled, text that extends the current text
fades in like Self::push_str would; any other replacement shows at
once.
Sourcepub fn push_str(&mut self, new_text: &str, cx: &mut Context<'_, Self>)
pub fn push_str(&mut self, new_text: &str, cx: &mut Context<'_, Self>)
Append partial text content to the existing text.
Sourcepub fn motion(self, motion: TextViewMotion) -> Self
pub fn motion(self, motion: TextViewMotion) -> Self
Set the motion policy; see TextViewMotion.
Sourcepub fn set_motion(&mut self, motion: TextViewMotion)
pub fn set_motion(&mut self, motion: TextViewMotion)
Set the motion policy; see TextViewMotion.
Sourcepub fn selected_text(&self) -> String
pub fn selected_text(&self) -> String
Return the selected text, in the view’s SelectionFormat.
Sourcepub fn selected_source_range(&self) -> Option<Range<usize>>
pub fn selected_source_range(&self) -> Option<Range<usize>>
Return the original Markdown source byte range corresponding to the rendered selection.
The range addresses the source passed to this Markdown TextView. It is
derived from parser positions retained by the rendered inline nodes, so
identical rendered text maps to the occurrence that was actually
selected. The result is one contiguous source range, so it includes any
Markdown delimiters between the selected rendered endpoints. HTML views
and selections without an exact source mapping return None. Select-all
in a Markdown view returns the full source range.
Sourcepub fn invalidate_inline_layout(&mut self, cx: &mut Context<'_, Self>)
pub fn invalidate_inline_layout(&mut self, cx: &mut Context<'_, Self>)
Remeasure inline resources after their prepared content or metrics change.
Call from the resource owner’s completion handler, through a weak entity when the task can outlive this view. This does not reparse the document. Existing logical selection is retained until the next selection gesture.
Sourcepub fn rendered_text(&self) -> RenderedText
pub fn rendered_text(&self) -> RenderedText
The text this view renders, which RangeHighlight ranges index.
This is the string plain copy produces, as of the last parse that landed; text set since then is not in it until its parse lands.
Sourcepub fn set_range_highlights(
&mut self,
highlights: impl IntoIterator<Item = RangeHighlight>,
cx: &mut Context<'_, Self>,
) -> Result<(), RangeHighlightError>
pub fn set_range_highlights( &mut self, highlights: impl IntoIterator<Item = RangeHighlight>, cx: &mut Context<'_, Self>, ) -> Result<(), RangeHighlightError>
Replace the range highlights, whose ranges index the current rendered text.
Compute ranges from the current Self::rendered_text and set them in
the same update. Search the new text again after its content changes.
A range crossing blocks paints in both, skipping their separator.
Text outside every block (separators, custom blocks, HTML blocks, and
inline objects) is left unpainted. Any invalid range rejects the set.
Highlights follow unchanged text through updates. Text appended while
streaming keeps earlier highlights; after a table edit, cells in and
after the edited row lose theirs because cells are known by position.
Text backgrounds such as <mark> paint over a highlight; inline code
backgrounds paint under it.
Sourcepub fn reveal_range(
&mut self,
range: Range<usize>,
cx: &mut Context<'_, Self>,
) -> Result<(), RangeHighlightError>
pub fn reveal_range( &mut self, range: Range<usize>, cx: &mut Context<'_, Self>, ) -> Result<(), RangeHighlightError>
Scroll the line range starts on into view, range indexing the
current rendered text, as with Self::set_range_highlights.
A Self::scrollable view scrolls itself. Otherwise the nearest
enclosing gpui::list scrolls, as long as the row holding the view is
laid out, so scroll to that row first when it may be off screen. Any
other scroll container scrolls through
TextView::on_reveal. An empty
range reveals the line of its position; a range in text that belongs
to no block’s text, such as a custom block’s, scrolls its whole block
into a scrollable view.
Only the latest reveal is carried out. It follows the content as range highlights do, and it is dropped when its text changes, when the view clamps its lines, or when it cannot be shown within a second, so it never scrolls long after it was asked for. A whole block taller than the view, scrolled to from below, shows its end.
Revealing is best effort: Ok(()) means the range is valid for the
current text and the request was taken, not that the view has
scrolled. A dropped request is not reported.
Sourcepub fn clear_range_highlights(&mut self, cx: &mut Context<'_, Self>)
pub fn clear_range_highlights(&mut self, cx: &mut Context<'_, Self>)
Remove all range highlights.
Sourcepub fn clear_selection(&mut self, cx: &mut Context<'_, Self>)
pub fn clear_selection(&mut self, cx: &mut Context<'_, Self>)
Clear the current text selection.
Sourcepub fn select_all(&mut self, cx: &mut Context<'_, Self>)
pub fn select_all(&mut self, cx: &mut Context<'_, Self>)
Select all rendered text in this view.
Trait Implementations§
Source§impl Render for TextViewState
impl Render for TextViewState
Auto Trait Implementations§
impl !RefUnwindSafe for TextViewState
impl !Send for TextViewState
impl !Sync for TextViewState
impl !UnwindSafe for TextViewState
impl Freeze for TextViewState
impl Unpin for TextViewState
impl UnsafeUnpin for TextViewState
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