Skip to main content

TextViewState

Struct TextViewState 

Source
pub struct TextViewState { /* private fields */ }
Expand description

The state of a TextView.

Implementations§

Source§

impl TextViewState

Source

pub fn markdown(text: &str, cx: &mut Context<'_, Self>) -> Self

Create a Markdown TextViewState.

Source

pub fn html(text: &str, cx: &mut Context<'_, Self>) -> Self

Create a HTML TextViewState.

Source

pub fn selectable(self, selectable: bool) -> Self

Set whether the text is selectable, default false.

Source

pub fn set_selectable(&mut self, selectable: bool, cx: &mut Context<'_, Self>)

Set whether the text is selectable, default false.

Source

pub fn selection_format(self, selection_format: SelectionFormat) -> Self

Source

pub fn set_selection_format( &mut self, selection_format: SelectionFormat, cx: &mut Context<'_, Self>, )

Source

pub fn scrollable(self, scrollable: bool) -> Self

Set whether the text view scrolls internally, default false.

Source

pub fn set_scrollable(&mut self, scrollable: bool, cx: &mut Context<'_, Self>)

Set whether the text view scrolls internally, default false.

Source

pub fn is_clamped(&self) -> bool

Whether the last painted frame clipped content because of TextView::max_lines.

Source

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.

Source

pub fn push_str(&mut self, new_text: &str, cx: &mut Context<'_, Self>)

Append partial text content to the existing text.

Source

pub fn motion(self, motion: TextViewMotion) -> Self

Set the motion policy; see TextViewMotion.

Source

pub fn set_motion(&mut self, motion: TextViewMotion)

Set the motion policy; see TextViewMotion.

Source

pub fn selected_text(&self) -> String

Return the selected text, in the view’s SelectionFormat.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear_range_highlights(&mut self, cx: &mut Context<'_, Self>)

Remove all range highlights.

Source

pub fn clear_selection(&mut self, cx: &mut Context<'_, Self>)

Clear the current text selection.

Source

pub fn select_all(&mut self, cx: &mut Context<'_, Self>)

Select all rendered text in this view.

Trait Implementations§

Source§

impl Render for TextViewState

Source§

fn render( &mut self, window: &mut Window, cx: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more