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>
This commit is contained in:
Richard Moe Gustavsen 2015-12-11 10:57:16 +01:00
parent 0b10d41c3d
commit e362774df2

View File

@ -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