Compute grapheme index in find_cursor_position for TextInput
This commit is contained in:
parent
51844c5d0c
commit
26e902f7d8
2 changed files with 13 additions and 15 deletions
|
|
@ -1193,17 +1193,26 @@ where
|
|||
let size = size.unwrap_or_else(|| renderer.default_size());
|
||||
|
||||
let offset = offset(renderer, text_bounds, font, size, value, state);
|
||||
let value = value.to_string();
|
||||
|
||||
renderer
|
||||
let char_offset = renderer
|
||||
.hit_test(
|
||||
&value.to_string(),
|
||||
&value,
|
||||
size,
|
||||
font,
|
||||
Size::INFINITY,
|
||||
Point::new(x + offset, text_bounds.height / 2.0),
|
||||
true,
|
||||
)
|
||||
.map(text::Hit::cursor)
|
||||
.map(text::Hit::cursor)?;
|
||||
|
||||
Some(
|
||||
unicode_segmentation::UnicodeSegmentation::graphemes(
|
||||
&value[..char_offset],
|
||||
true,
|
||||
)
|
||||
.count(),
|
||||
)
|
||||
}
|
||||
|
||||
const CURSOR_BLINK_INTERVAL_MILLIS: u128 = 500;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue