Base selection on the top of the line
This commit is contained in:
parent
10bf182c5d
commit
e8b10fd675
2 changed files with 11 additions and 6 deletions
|
|
@ -121,6 +121,8 @@ pub struct LayoutRun<'a> {
|
|||
pub glyphs: &'a [LayoutGlyph],
|
||||
/// Y offset to baseline of line
|
||||
pub line_y: f32,
|
||||
/// Y offset to top of line
|
||||
pub line_top: f32,
|
||||
/// Width of line
|
||||
pub line_w: f32,
|
||||
}
|
||||
|
|
@ -246,15 +248,16 @@ impl<'b> Iterator for LayoutRunIter<'b> {
|
|||
continue;
|
||||
}
|
||||
|
||||
let line_y = self
|
||||
let line_top = self
|
||||
.total_layout
|
||||
.saturating_sub(self.buffer.scroll)
|
||||
.saturating_sub(1) as f32
|
||||
* self.buffer.metrics.line_height;
|
||||
let glyph_height = layout_line.max_ascent + layout_line.max_descent;
|
||||
let centering_offset = (self.buffer.metrics.line_height - glyph_height) / 2.0;
|
||||
let line_y = line_top + centering_offset + layout_line.max_ascent;
|
||||
|
||||
if line_y + centering_offset > self.buffer.height {
|
||||
if line_top + centering_offset > self.buffer.height {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +268,8 @@ impl<'b> Iterator for LayoutRunIter<'b> {
|
|||
text: line.text(),
|
||||
rtl: shape.rtl,
|
||||
glyphs: &layout_line.glyphs,
|
||||
line_y: line_y + centering_offset + layout_line.max_ascent,
|
||||
line_y,
|
||||
line_top,
|
||||
line_w: layout_line.w,
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -702,6 +702,7 @@ impl Edit for Editor {
|
|||
for run in self.buffer.layout_runs() {
|
||||
let line_i = run.line_i;
|
||||
let line_y = run.line_y;
|
||||
let line_top = run.line_top;
|
||||
|
||||
let cursor_glyph_opt = |cursor: &Cursor| -> Option<(usize, f32)> {
|
||||
if cursor.line == line_i {
|
||||
|
|
@ -779,7 +780,7 @@ impl Edit for Editor {
|
|||
} else if let Some((min, max)) = range_opt.take() {
|
||||
f(
|
||||
min,
|
||||
(line_y - font_size) as i32,
|
||||
line_top as i32,
|
||||
cmp::max(0, max - min) as u32,
|
||||
line_height as u32,
|
||||
Color::rgba(color.r(), color.g(), color.b(), 0x33),
|
||||
|
|
@ -805,7 +806,7 @@ impl Edit for Editor {
|
|||
}
|
||||
f(
|
||||
min,
|
||||
(line_y - font_size) as i32,
|
||||
line_top as i32,
|
||||
cmp::max(0, max - min) as u32,
|
||||
line_height as u32,
|
||||
Color::rgba(color.r(), color.g(), color.b(), 0x33),
|
||||
|
|
@ -843,7 +844,7 @@ impl Edit for Editor {
|
|||
|
||||
f(
|
||||
x,
|
||||
(line_y - font_size) as i32,
|
||||
line_top as i32,
|
||||
1,
|
||||
line_height as u32,
|
||||
self.cursor.color.unwrap_or(color),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue