From bf50bf737b6198a64756ce96ff9852c36e6f3066 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 20 May 2014 12:51:37 +0200 Subject: [PATCH] iOS: don't report negative selection ranges for backspace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/plugins/platforms/ios/quiview_textinput.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/platforms/ios/quiview_textinput.mm b/src/plugins/platforms/ios/quiview_textinput.mm index 3f6c6d1256..79e3897013 100644 --- a/src/plugins/platforms/ios/quiview_textinput.mm +++ b/src/plugins/platforms/ios/quiview_textinput.mm @@ -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