From e12ecb5865980b8aa39fb259e315e2d95eb170a9 Mon Sep 17 00:00:00 2001 From: wuwbobo2021 Date: Fri, 27 Dec 2024 10:20:19 +0800 Subject: [PATCH] Fix TextEdit crashing on Android (#7203) --- internal/renderers/skia/textlayout.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/renderers/skia/textlayout.rs b/internal/renderers/skia/textlayout.rs index ce107286f58..131ad132d37 100644 --- a/internal/renderers/skia/textlayout.rs +++ b/internal/renderers/skia/textlayout.rs @@ -269,6 +269,13 @@ pub fn cursor_rect( ); } + // This is needed in case of the cursor is moving to the end of the text (#7203). + let cursor_pos = cursor_pos.min(string.len()); + // Not doing this check may cause crashing with non-ASCII text. + if !string.is_char_boundary(cursor_pos) { + return Default::default(); + } + // SkParagraph::getRectsForRange() does not report the text box of a trailing newline // correctly. Use the last line's metrics to get the correct coordinates (#3590). if cursor_pos == string.len()