From 1c75f59588694557caba69c2fc173dd8f1d7f514 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 8 Jan 2020 14:48:12 +0100 Subject: iOS: Handle positionFromPosition out of bounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on the documentation for positionFromPosition, if the resulting position is less than 0 or longer than the text, then we should return nil. This fixes problems with placement of the cursor and selection rectangle when auto-completion is used. Fixes: QTBUG-79445 Change-Id: I44a18881527a8a22012fe5fcbbc3216e60c48bc9 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiostextresponder.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm index 1bc9744528..a3350bda87 100644 --- a/src/plugins/platforms/ios/qiostextresponder.mm +++ b/src/plugins/platforms/ios/qiostextresponder.mm @@ -745,7 +745,11 @@ - (UITextPosition *)positionFromPosition:(UITextPosition *)position offset:(NSInteger)offset { int p = static_cast(position).index; - return [QUITextPosition positionWithIndex:p + offset]; + const int posWithIndex = p + offset; + const int textLength = [self currentImeState:Qt::ImSurroundingText].toString().length(); + if (posWithIndex < 0 || posWithIndex > textLength) + return nil; + return [QUITextPosition positionWithIndex:posWithIndex]; } - (UITextPosition *)positionFromPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction offset:(NSInteger)offset -- cgit v1.2.3