summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-12-11 10:57:16 +0100
committerRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-12-17 13:47:14 +0000
commite362774df22846e100237739c0cb7190100d265b (patch)
tree61932273f8ebe183c46f022765282676fdc463ca
parent0b10d41c3db0d1a43e754a2bd923a0df8915d0e5 (diff)
iOS: include marked text when reporting IM textInRange and endOfDocument
[UITextInput textInRange] is sparsely documented, but it turns out that unconfirmed marked text should be seen as a part of the text document. This is different from Qt IM (ImSurroundingText), which handles marked text on the side. The reason we can assume this is that the range we are given as argument to textInRange exceeds the documents length when having marked text appended to the end, suggesting that it tries to read / verify the current marked text. In addition, keyboards like Japanese-Kana will not update and function correctly unless marked text is included. Note that the docs seems to imply that you cannot have marked text and text selection at the same time, unless the selection is contained within the marked text (using the dedicated selectedRange argument to setMarkedText). If this turns out to be incorrect, we might need to adjust the methods dealing with selection to also include marked text as well. Task-number: QTBUG-49946 Change-Id: Ifedd792ec66db435806f57fca157e1abbbf121a8 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
-rw-r--r--src/plugins/platforms/ios/qiostextresponder.mm14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm
index 770dadd3e4..2e8c0cb4db 100644
--- a/src/plugins/platforms/ios/qiostextresponder.mm
+++ b/src/plugins/platforms/ios/qiostextresponder.mm
@@ -613,7 +613,8 @@
- (UITextPosition *)endOfDocument
{
- int endPosition = [self currentImeState:Qt::ImSurroundingText].toString().length();
+ QString surroundingText = [self currentImeState:Qt::ImSurroundingText].toString();
+ int endPosition = surroundingText.length() + m_markedText.length();
return [QUITextPosition positionWithIndex:endPosition];
}
@@ -644,9 +645,18 @@
- (NSString *)textInRange:(UITextRange *)range
{
+ QString text = [self currentImeState:Qt::ImSurroundingText].toString();
+ if (!m_markedText.isEmpty()) {
+ // [UITextInput textInRange] is sparsely documented, but it turns out that unconfirmed
+ // marked text should be seen as a part of the text document. This is different from
+ // ImSurroundingText, which excludes it.
+ int cursorPos = [self currentImeState:Qt::ImCursorPosition].toInt();
+ text = text.left(cursorPos) + m_markedText + text.mid(cursorPos);
+ }
+
int s = static_cast<QUITextPosition *>([range start]).index;
int e = static_cast<QUITextPosition *>([range end]).index;
- return [self currentImeState:Qt::ImSurroundingText].toString().mid(s, e - s).toNSString();
+ return text.mid(s, e - s).toNSString();
}
- (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange