Lines

Struct Lines 

Source
pub struct Lines {
    pub font_sizes: RefCell<Rc<dyn LineFontSizeProvider>>,
    pub layout_event: Listener<LayoutEvent>,
    /* private fields */
}
Expand description

The main structure for tracking visual line information.

Fields§

§font_sizes: RefCell<Rc<dyn LineFontSizeProvider>>

This is inside out from the usual way of writing Arc-RefCells due to sometimes wanting to swap out font sizes, while also grabbing an Arc to hold.

An Arc<RefCell<_>> has the issue that with a dyn it can’t know they’re the same size if you were to assign. So this allows us to swap out the Arc, though it does mean that the other holders of the Arc don’t get the new version. That is fine currently.

§layout_event: Listener<LayoutEvent>

Implementations§

Source§

impl Lines

Source

pub fn new( cx: Scope, font_sizes: RefCell<Rc<dyn LineFontSizeProvider>>, ) -> Lines

Source

pub fn wrap(&self) -> ResolvedWrap

The current wrapping style

Source

pub fn set_wrap(&self, wrap: ResolvedWrap)

Set the wrapping style

Does nothing if the wrapping style is the same as the current one. Will trigger a clear of the text layouts if the wrapping style is different.

Source

pub fn max_width(&self) -> f64

The max width of the text layouts displayed

Source

pub fn is_linear(&self, text_prov: impl TextLayoutProvider) -> bool

Check if the lines can be modelled as a purely linear file.

If true this makes various operations simpler because there is a one-to-one correspondence between visual lines and buffer lines.

However, if there is wrapping or any multiline phantom text, then we can’t rely on that.

TODO:? We could be smarter about various pieces.

  • If there was no lines that exceeded the wrap width then we could do the fast path
    • Would require tracking that but might not be too hard to do it whenever we create a text layout
  • is_linear could be up to some line, which allows us to make at least the earliest parts before any wrapping were faster. However, early lines are faster to calculate anyways.
Source

pub fn font_size(&self, line: usize) -> usize

Get the font size that Self::font_sizes provides

Source

pub fn last_vline(&self, text_prov: impl TextLayoutProvider) -> VLine

Get the last visual line of the file.

Cached.

Source

pub fn clear_last_vline(&self)

Clear the cache for the last vline

Source

pub fn last_rvline(&self, text_prov: impl TextLayoutProvider) -> RVLine

The last relative visual line.

Cheap, so not cached

Source

pub fn num_vlines(&self, text_prov: impl TextLayoutProvider) -> usize

‘len’ version of Lines::last_vline

Cached.

Source

pub fn get_init_text_layout( &self, cache_rev: u64, config_id: ConfigId, text_prov: impl TextLayoutProvider, line: usize, trigger: bool, ) -> Arc<TextLayoutLine>

Get the text layout for the given buffer line number. This will create the text layout if it doesn’t exist.

trigger (default to true) decides whether the creation of the text layout should trigger the LayoutEvent::CreatedLayout event.

This will check the config_id, which decides whether it should clear out the text layout cache.

Source

pub fn try_get_text_layout( &self, cache_rev: u64, config_id: ConfigId, line: usize, ) -> Option<Arc<TextLayoutLine>>

Try to get the text layout for the given line number.

This will check the config_id, which decides whether it should clear out the text layout cache.

Source

pub fn init_line_interval( &self, cache_rev: u64, config_id: ConfigId, text_prov: &impl TextLayoutProvider, lines: impl Iterator<Item = usize>, trigger: bool, )

Initialize the text layout of every line in the real line interval.

trigger (default to true) decides whether the creation of the text layout should trigger the LayoutEvent::CreatedLayout event.

Source

pub fn init_all( &self, cache_rev: u64, config_id: ConfigId, text_prov: &impl TextLayoutProvider, trigger: bool, )

Initialize the text layout of every line in the file. This should typically not be used.

trigger (default to true) decides whether the creation of the text layout should trigger the LayoutEvent::CreatedLayout event.

Source

pub fn iter_vlines( &self, text_prov: impl TextLayoutProvider, backwards: bool, start: VLine, ) -> impl Iterator<Item = VLineInfo>

Iterator over VLineInfos, starting at start_line.

Source

pub fn iter_vlines_over( &self, text_prov: impl TextLayoutProvider, backwards: bool, start: VLine, end: VLine, ) -> impl Iterator<Item = VLineInfo>

Iterator over VLineInfos, starting at start_line and ending at end_line.

start_line..end_line

Source

pub fn iter_rvlines( &self, text_prov: impl TextLayoutProvider, backwards: bool, start: RVLine, ) -> impl Iterator<Item = VLineInfo<()>>

Iterator over relative VLineInfos, starting at the rvline, start_line.

This is preferable over iter_vlines if you do not need to absolute visual line value and can provide the buffer line.

Source

pub fn iter_rvlines_over( &self, text_prov: impl TextLayoutProvider, backwards: bool, start: RVLine, end_line: usize, ) -> impl Iterator<Item = VLineInfo<()>>

Iterator over relative VLineInfos, starting at the rvline start_line and ending at the buffer line end_line.

start_line..end_line

This is preferable over iter_vlines if you do not need the absolute visual line value and you can provide the buffer line.

Source

pub fn iter_vlines_init( &self, text_prov: impl TextLayoutProvider + Clone, cache_rev: u64, config_id: ConfigId, start: VLine, trigger: bool, ) -> impl Iterator<Item = VLineInfo>

Initialize the text layouts as you iterate over them.

Source

pub fn iter_vlines_init_over( &self, text_prov: impl TextLayoutProvider + Clone, cache_rev: u64, config_id: ConfigId, start: VLine, end: VLine, trigger: bool, ) -> impl Iterator<Item = VLineInfo>

Iterator over VLineInfos, starting at start_line and ending at end_line. start_line..end_line

Initializes the text layouts as you iterate over them.

trigger (default to true) decides whether the creation of the text layout should trigger the LayoutEvent::CreatedLayout event.

Source

pub fn iter_rvlines_init( &self, text_prov: impl TextLayoutProvider + Clone, cache_rev: u64, config_id: ConfigId, start: RVLine, trigger: bool, ) -> impl Iterator<Item = VLineInfo<()>>

Iterator over relative VLineInfos, starting at the rvline, start_line and ending at the buffer line end_line.

start_line..end_line

trigger (default to true) decides whether the creation of the text layout should trigger the LayoutEvent::CreatedLayout event.

Source

pub fn vline_of_offset( &self, text_prov: &impl TextLayoutProvider, offset: usize, affinity: CursorAffinity, ) -> VLine

Get the visual line of the offset.

affinity decides whether an offset at a soft line break is considered to be on the previous line or the next line.

If affinity is CursorAffinity::Forward and is at the very end of the wrapped line, then the offset is considered to be on the next vline.

Source

pub fn vline_col_of_offset( &self, text_prov: &impl TextLayoutProvider, offset: usize, affinity: CursorAffinity, ) -> (VLine, usize)

Get the visual line and column of the given offset.

The column is before phantom text is applied and is into the overall line, not the individual visual line.

Source

pub fn offset_of_vline( &self, text_prov: &impl TextLayoutProvider, vline: VLine, ) -> usize

Get the nearest offset to the start of the visual line

Source

pub fn vline_of_line( &self, text_prov: &impl TextLayoutProvider, line: usize, ) -> VLine

Get the first visual line of the buffer line.

Source

pub fn vline_of_rvline( &self, text_prov: &impl TextLayoutProvider, rvline: RVLine, ) -> VLine

Find the matching visual line for the given relative visual line.

Source

pub fn rvline_of_offset( &self, text_prov: &impl TextLayoutProvider, offset: usize, affinity: CursorAffinity, ) -> RVLine

Get the relative visual line of the offset.

affinity decides whether an offset at a soft line break is considered to be on the previous line or the next line. If affinity is CursorAffinity::Forward and is at the very end of the wrapped line, then the offset is considered to be on the next rvline.

Source

pub fn rvline_col_of_offset( &self, text_prov: &impl TextLayoutProvider, offset: usize, affinity: CursorAffinity, ) -> (RVLine, usize)

Get the relative visual line and column of the given offset

The column is before phantom text is applied and is into the overall line, not the individual visual line.

Source

pub fn offset_of_rvline( &self, text_prov: &impl TextLayoutProvider, _: RVLine, ) -> usize

Get the offset of a relative visual line

Source

pub fn rvline_of_line( &self, text_prov: &impl TextLayoutProvider, line: usize, ) -> RVLine

Get the relative visual line of the buffer line

Source

pub fn check_cache(&self, cache_rev: u64, config_id: ConfigId)

Check whether the cache rev or config id has changed, clearing the cache if it has.

Source

pub fn check_cache_rev(&self, cache_rev: u64)

Check whether the text layout cache revision is different.

Clears the layouts and updates the cache rev if it was different.

Source

pub fn clear(&self, cache_rev: u64, config_id: Option<ConfigId>)

Clear the text layouts with a given cache revision

Source

pub fn clear_unchanged(&self)

Clear the layouts and vline without changing the cache rev or config id.

Auto Trait Implementations§

§

impl !Freeze for Lines

§

impl !RefUnwindSafe for Lines

§

impl !Send for Lines

§

impl !Sync for Lines

§

impl Unpin for Lines

§

impl !UnwindSafe for Lines

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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

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

Source§

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