summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-01-08 14:48:12 +0100
committerAndy Shaw <andy.shaw@qt.io>2020-01-09 15:28:43 +0100
commit1c75f59588694557caba69c2fc173dd8f1d7f514 (patch)
treeca25a230274842a8ea2a25c0a144549dcb8d17c8 /src
parent1e42c97cf055ac20352d20150e2786c14565ea2b (diff)
iOS: Handle positionFromPosition out of bounds
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ø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/ios/qiostextresponder.mm6
1 files changed, 5 insertions, 1 deletions
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<QUITextPosition *>(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