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
impl Lines
pub fn new( cx: Scope, font_sizes: RefCell<Rc<dyn LineFontSizeProvider>>, ) -> Lines
Sourcepub fn wrap(&self) -> ResolvedWrap
pub fn wrap(&self) -> ResolvedWrap
The current wrapping style
Sourcepub fn set_wrap(&self, wrap: ResolvedWrap)
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.
Sourcepub fn is_linear(&self, text_prov: impl TextLayoutProvider) -> bool
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_linearcould 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.
Sourcepub fn font_size(&self, line: usize) -> usize
pub fn font_size(&self, line: usize) -> usize
Get the font size that Self::font_sizes provides
Sourcepub fn last_vline(&self, text_prov: impl TextLayoutProvider) -> VLine
pub fn last_vline(&self, text_prov: impl TextLayoutProvider) -> VLine
Get the last visual line of the file.
Cached.
Sourcepub fn clear_last_vline(&self)
pub fn clear_last_vline(&self)
Clear the cache for the last vline
Sourcepub fn last_rvline(&self, text_prov: impl TextLayoutProvider) -> RVLine
pub fn last_rvline(&self, text_prov: impl TextLayoutProvider) -> RVLine
The last relative visual line.
Cheap, so not cached
Sourcepub fn num_vlines(&self, text_prov: impl TextLayoutProvider) -> usize
pub fn num_vlines(&self, text_prov: impl TextLayoutProvider) -> usize
‘len’ version of Lines::last_vline
Cached.
Sourcepub fn get_init_text_layout(
&self,
cache_rev: u64,
config_id: ConfigId,
text_prov: impl TextLayoutProvider,
line: usize,
trigger: bool,
) -> Arc<TextLayoutLine>
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.
Sourcepub fn try_get_text_layout(
&self,
cache_rev: u64,
config_id: ConfigId,
line: usize,
) -> Option<Arc<TextLayoutLine>>
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.
Sourcepub fn init_line_interval(
&self,
cache_rev: u64,
config_id: ConfigId,
text_prov: &impl TextLayoutProvider,
lines: impl Iterator<Item = usize>,
trigger: bool,
)
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.
Sourcepub fn init_all(
&self,
cache_rev: u64,
config_id: ConfigId,
text_prov: &impl TextLayoutProvider,
trigger: bool,
)
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.
Sourcepub fn iter_vlines(
&self,
text_prov: impl TextLayoutProvider,
backwards: bool,
start: VLine,
) -> impl Iterator<Item = VLineInfo>
pub fn iter_vlines( &self, text_prov: impl TextLayoutProvider, backwards: bool, start: VLine, ) -> impl Iterator<Item = VLineInfo>
Iterator over VLineInfos, starting at start_line.
Sourcepub fn iter_vlines_over(
&self,
text_prov: impl TextLayoutProvider,
backwards: bool,
start: VLine,
end: VLine,
) -> impl Iterator<Item = VLineInfo>
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
Sourcepub fn iter_rvlines(
&self,
text_prov: impl TextLayoutProvider,
backwards: bool,
start: RVLine,
) -> impl Iterator<Item = VLineInfo<()>>
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.
Sourcepub fn iter_rvlines_over(
&self,
text_prov: impl TextLayoutProvider,
backwards: bool,
start: RVLine,
end_line: usize,
) -> impl Iterator<Item = VLineInfo<()>>
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.
Sourcepub fn iter_vlines_init(
&self,
text_prov: impl TextLayoutProvider + Clone,
cache_rev: u64,
config_id: ConfigId,
start: VLine,
trigger: bool,
) -> impl Iterator<Item = VLineInfo>
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.
Sourcepub 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>
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.
Sourcepub fn iter_rvlines_init(
&self,
text_prov: impl TextLayoutProvider + Clone,
cache_rev: u64,
config_id: ConfigId,
start: RVLine,
trigger: bool,
) -> impl Iterator<Item = VLineInfo<()>>
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.
Sourcepub fn vline_of_offset(
&self,
text_prov: &impl TextLayoutProvider,
offset: usize,
affinity: CursorAffinity,
) -> VLine
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.
Sourcepub fn vline_col_of_offset(
&self,
text_prov: &impl TextLayoutProvider,
offset: usize,
affinity: CursorAffinity,
) -> (VLine, usize)
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.
Sourcepub fn offset_of_vline(
&self,
text_prov: &impl TextLayoutProvider,
vline: VLine,
) -> usize
pub fn offset_of_vline( &self, text_prov: &impl TextLayoutProvider, vline: VLine, ) -> usize
Get the nearest offset to the start of the visual line
Sourcepub fn vline_of_line(
&self,
text_prov: &impl TextLayoutProvider,
line: usize,
) -> VLine
pub fn vline_of_line( &self, text_prov: &impl TextLayoutProvider, line: usize, ) -> VLine
Get the first visual line of the buffer line.
Sourcepub fn vline_of_rvline(
&self,
text_prov: &impl TextLayoutProvider,
rvline: RVLine,
) -> VLine
pub fn vline_of_rvline( &self, text_prov: &impl TextLayoutProvider, rvline: RVLine, ) -> VLine
Find the matching visual line for the given relative visual line.
Sourcepub fn rvline_of_offset(
&self,
text_prov: &impl TextLayoutProvider,
offset: usize,
affinity: CursorAffinity,
) -> RVLine
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.
Sourcepub fn rvline_col_of_offset(
&self,
text_prov: &impl TextLayoutProvider,
offset: usize,
affinity: CursorAffinity,
) -> (RVLine, usize)
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.
Sourcepub fn offset_of_rvline(
&self,
text_prov: &impl TextLayoutProvider,
_: RVLine,
) -> usize
pub fn offset_of_rvline( &self, text_prov: &impl TextLayoutProvider, _: RVLine, ) -> usize
Get the offset of a relative visual line
Sourcepub fn rvline_of_line(
&self,
text_prov: &impl TextLayoutProvider,
line: usize,
) -> RVLine
pub fn rvline_of_line( &self, text_prov: &impl TextLayoutProvider, line: usize, ) -> RVLine
Get the relative visual line of the buffer line
Sourcepub fn check_cache(&self, cache_rev: u64, config_id: ConfigId)
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.
Sourcepub fn check_cache_rev(&self, cache_rev: u64)
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.
Sourcepub fn clear(&self, cache_rev: u64, config_id: Option<ConfigId>)
pub fn clear(&self, cache_rev: u64, config_id: Option<ConfigId>)
Clear the text layouts with a given cache revision
Sourcepub fn clear_unchanged(&self)
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> 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
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