diff options
| author | 2023-02-10 20:03:33 +0100 | |
|---|---|---|
| committer | 2023-02-24 13:37:32 +0100 | |
| commit | 26e902f7d84290f8163a25c37488d29db4fc0708 (patch) | |
| tree | 2ef873ef3b827449cdfd07a74c52665a172d58ad /native/src/widget | |
| parent | 51844c5d0c7f7c9b65c56330862b69f0baa0e3c1 (diff) | |
| download | iced-26e902f7d84290f8163a25c37488d29db4fc0708.tar.gz iced-26e902f7d84290f8163a25c37488d29db4fc0708.tar.bz2 iced-26e902f7d84290f8163a25c37488d29db4fc0708.zip | |
Compute grapheme index in `find_cursor_position` for `TextInput`
Diffstat (limited to '')
| -rw-r--r-- | native/src/widget/text_input.rs | 15 | 
1 files changed, 12 insertions, 3 deletions
| diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index f51416e1..65a9bd3b 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -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; | 
