Merge pull request #576 from zed-industries/cursor-shape

Add support for rendering the cursor as a Block and Underscore

Co-authored-by: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Keith Simmons
2022-03-11 11:51:24 -08:00
committed by GitHub
co-authored by Max Brunsfeld
3 changed files with 114 additions and 13 deletions
+18 -2
View File
@@ -186,7 +186,7 @@ pub struct Run {
pub glyphs: Vec<Glyph>,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct Glyph {
pub id: GlyphId,
pub position: Vector2F,
@@ -210,10 +210,14 @@ impl Line {
self.layout.width
}
pub fn font_size(&self) -> f32 {
self.layout.font_size
}
pub fn x_for_index(&self, index: usize) -> f32 {
for run in &self.layout.runs {
for glyph in &run.glyphs {
if glyph.index == index {
if glyph.index >= index {
return glyph.position.x();
}
}
@@ -221,6 +225,18 @@ impl Line {
self.layout.width
}
pub fn font_for_index(&self, index: usize) -> Option<FontId> {
for run in &self.layout.runs {
for glyph in &run.glyphs {
if glyph.index >= index {
return Some(run.font_id);
}
}
}
None
}
pub fn index_for_x(&self, x: f32) -> Option<usize> {
if x >= self.layout.width {
None