Merge branch 'main' into zed2

This commit is contained in:
Conrad Irwin 2023-10-27 10:55:15 +02:00
commit 4a6a17d866
238 changed files with 17140 additions and 6659 deletions

View file

@ -266,6 +266,8 @@ impl Line {
self.layout.len == 0
}
/// index_for_x returns the character containing the given x coordinate.
/// (e.g. to handle a mouse-click)
pub fn index_for_x(&self, x: f32) -> Option<usize> {
if x >= self.layout.width {
None
@ -281,6 +283,28 @@ impl Line {
}
}
/// closest_index_for_x returns the character boundary closest to the given x coordinate
/// (e.g. to handle aligning up/down arrow keys)
pub fn closest_index_for_x(&self, x: f32) -> usize {
let mut prev_index = 0;
let mut prev_x = 0.0;
for run in self.layout.runs.iter() {
for glyph in run.glyphs.iter() {
if glyph.position.x() >= x {
if glyph.position.x() - x < x - prev_x {
return glyph.index;
} else {
return prev_index;
}
}
prev_index = glyph.index;
prev_x = glyph.position.x();
}
}
prev_index
}
pub fn paint(
&self,
origin: Vector2F,