Refactor of scroll and shaping

- Scroll is identified by line index and layout index, instead of just
  layout index
- Shaping has the option to prune, where caches outside of the scroll
  view are cleared
- Syntax editor no longer requires layout of all lines, only of lines
  inside scroll
- BufferLine has a metadata field that can be used by other abstractions
  to know when text was changed
This commit is contained in:
Jeremy Soller 2023-12-15 13:37:59 -07:00
parent e7261fc06e
commit d0b4b4635e
16 changed files with 213 additions and 159 deletions

View file

@ -3,7 +3,7 @@ use crate::Color;
/// Current cursor location
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]
pub struct Cursor {
/// Text line the cursor is on
/// Index of [`BufferLine`] in [`Buffer::lines`]
pub line: usize,
/// First-byte-index of glyph at cursor (will insert behind this glyph)
pub index: usize,
@ -81,8 +81,11 @@ impl Affinity {
/// The position of a cursor within a [`Buffer`].
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct LayoutCursor {
/// Index of [`BufferLine`] in [`Buffer::lines`]
pub line: usize,
/// Index of [`LayoutLine`] in [`BufferLine::layout`]
pub layout: usize,
/// Index of [`LayoutGlyph`] in [`LayoutLine::glyphs`]
pub glyph: usize,
}
@ -145,3 +148,14 @@ pub enum Motion {
/// Move cursor to specific line
GotoLine(usize),
}
/// Scroll position in [`Buffer`]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Scroll {
/// Index of [`BufferLine`] in [`Buffer::lines`]. This will be adjusted as needed if layout is
/// out of bounds
pub line: usize,
/// Index of [`LayoutLine`] in [`BufferLine::layout`]. This will be adjusted as needed
/// if it is negative or exceeds the number of layout lines
pub layout: i32,
}