Merge pull request #3072 from EmmanuelDodoo/master
Fixed hit span for paragraph
This commit is contained in:
commit
5206f9ab91
1 changed files with 16 additions and 14 deletions
|
|
@ -271,28 +271,30 @@ impl core::text::Paragraph for Paragraph {
|
||||||
let cursor = internal.buffer.hit(point.x, point.y)?;
|
let cursor = internal.buffer.hit(point.x, point.y)?;
|
||||||
let line = internal.buffer.lines.get(cursor.line)?;
|
let line = internal.buffer.lines.get(cursor.line)?;
|
||||||
|
|
||||||
let mut last_glyph = None;
|
if cursor.index >= line.text().len() {
|
||||||
let mut glyphs = line
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let index = match cursor.affinity {
|
||||||
|
cosmic_text::Affinity::Before => cursor.index.saturating_sub(1),
|
||||||
|
cosmic_text::Affinity::After => cursor.index,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut hit = None;
|
||||||
|
let glyphs = line
|
||||||
.layout_opt()
|
.layout_opt()
|
||||||
.as_ref()?
|
.as_ref()?
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|line| line.glyphs.iter())
|
.flat_map(|line| line.glyphs.iter());
|
||||||
.peekable();
|
|
||||||
|
|
||||||
while let Some(glyph) = glyphs.peek() {
|
for glyph in glyphs {
|
||||||
if glyph.start <= cursor.index && cursor.index < glyph.end {
|
if glyph.start <= index && index < glyph.end {
|
||||||
|
hit = Some(glyph);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_glyph = glyphs.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let glyph = match cursor.affinity {
|
Some(hit?.metadata)
|
||||||
cosmic_text::Affinity::Before => last_glyph,
|
|
||||||
cosmic_text::Affinity::After => glyphs.next(),
|
|
||||||
}?;
|
|
||||||
|
|
||||||
Some(glyph.metadata)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span_bounds(&self, index: usize) -> Vec<Rectangle> {
|
fn span_bounds(&self, index: usize) -> Vec<Rectangle> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue