use std::{ops::Range, rc::Rc}; use gpui::{Bounds, Half, Pixels, ShapedLine, TextAlign, px}; use super::{WrappingIndent, display_map::LineLayout}; #[derive(Clone, Default)] pub(crate) struct WhitespaceIndicators { pub(crate) space: ShapedLine, pub(crate) tab: ShapedLine, } #[derive(Clone)] pub(super) struct LastLayout { pub(super) visible_range: Range, pub(super) visible_buffer_lines: Vec, pub(super) visible_line_byte_offsets: Vec, pub(super) visible_top: Pixels, pub(super) visible_range_offset: Range, pub(super) lines: Rc>, pub(super) line_height: Pixels, pub(super) wrap_width: Option, pub(super) wrapping_indent: WrappingIndent, pub(super) line_number_width: Pixels, /// Width of one space in the editor font. /// /// Past the end of a line there are no glyphs to hit-test against, so this is the /// step used to measure how far past the end a pointer sits. pub(super) space_width: Pixels, pub(super) cursor_bounds: Option>, pub(super) text_align: TextAlign, pub(super) content_width: Pixels, } impl LastLayout { pub(crate) fn line(&self, row: usize) -> Option<&LineLayout> { let pos = self.visible_buffer_lines.binary_search(&row).ok()?; self.lines.get(pos) } pub(super) fn alignment_offset(&self, line_width: Pixels) -> Pixels { match self.text_align { TextAlign::Left => px(0.), TextAlign::Center => (self.content_width - line_width).half().max(px(0.)), TextAlign::Right => (self.content_width - line_width).max(px(0.)), } } }