pub trait TextLayoutProvider {
// Required methods
fn text(&self) -> Rope;
fn new_text_layout(
&self,
line: usize,
font_size: usize,
wrap: ResolvedWrap,
) -> Arc<TextLayoutLine>;
fn before_phantom_col(&self, line: usize, col: usize) -> usize;
fn has_multiline_phantom(&self) -> bool;
// Provided method
fn rope_text(&self) -> RopeTextVal { ... }
}Expand description
The TextLayoutProvider serves two primary roles:
- Providing the
Ropetext of the underlying file - Constructing the text layout for a given line
Note: text does not necessarily include every piece of text. The obvious example is phantom
text, which is not in the underlying buffer.
Using this trait rather than passing around something like Document allows the backend to be swapped out if needed. This would be useful if we ever wanted to reuse it across different views that did not naturally fit into our ‘document’ model. As well as when we want to extract the editor view code int a separate crate for Floem.
Required Methods§
fn text(&self) -> Rope
fn new_text_layout( &self, line: usize, font_size: usize, wrap: ResolvedWrap, ) -> Arc<TextLayoutLine>
Sourcefn before_phantom_col(&self, line: usize, col: usize) -> usize
fn before_phantom_col(&self, line: usize, col: usize) -> usize
Translate a column position into the position it would be before combining with the phantom text
Sourcefn has_multiline_phantom(&self) -> bool
fn has_multiline_phantom(&self) -> bool
Whether the text has any multiline phantom text.
This is used to determine whether we can use the fast route where the lines are linear, which also requires no wrapping.
This should be a conservative estimate, so if you aren’t bothering to check all of your phantom text then just return true.
Provided Methods§
Sourcefn rope_text(&self) -> RopeTextVal
fn rope_text(&self) -> RopeTextVal
Shorthand for getting a rope text version of text.
This MUST hold the same rope that text would return.