iOS: don't report negative selection ranges for backspace

Qt sometimes report that the selection anchor is placed before
the cursor when querying it for current selection. We need to
accomodate for this when reporting current selection back to
iOS, since it expects the range to always be positive.

When pressing backspace, iOS will select the letter that should be
deleted, and then call "deleteBackwards". If holding down backspace
for a while, it will start selecting whole words instead.
Since we reported negative ranges during this process, it caused
artifacts and stray letters to be drawn.

Task-number: QTBUG-39073
Change-Id: Ida9518307adce915adf49160b541a2f88637a0da
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2014-05-20 12:51:37 +02:00 committed by The Qt Project
parent 5283a6c87b
commit bf50bf737b

View File

@ -253,7 +253,7 @@ Q_GLOBAL_STATIC(StaticVariables, staticVariables);
- (UITextRange *)selectedTextRange {
int cursorPos = [self imValue:Qt::ImCursorPosition].toInt();
int anchorPos = [self imValue:Qt::ImAnchorPosition].toInt();
return [QUITextRange rangeWithNSRange:NSMakeRange(cursorPos, (anchorPos - cursorPos))];
return [QUITextRange rangeWithNSRange:NSMakeRange(qMin(cursorPos, anchorPos), qAbs(anchorPos - cursorPos))];
}
- (NSString *)textInRange:(UITextRange *)range