iOS: handle all directions when calculating positionFromPosition

The method is currently a bit buggy, since it does not take
UITextLayoutDirectionUp and UITextLayoutDirectionDown into account.

This patch is mostly for fixing something "just in case", since
we so far have not seen UIKit calling this method for those
directions unless a hardware keyboard is connected. And in
that case, we anyway override IM navigation by dealing
with the arrow keys explicit.

Since IM in Qt does not support getting the position above
or below the current position, we just return the current
position, making it a no-op.

Change-Id: I4bcb9e2a00ab4e3d785058d7ff7f4855142dabbc
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
Richard Moe Gustavsen 2015-08-03 12:59:01 +02:00
parent 97b525e3be
commit 21e1354d42

View File

@ -652,7 +652,17 @@
- (UITextPosition *)positionFromPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction offset:(NSInteger)offset
{
int p = static_cast<QUITextPosition *>(position).index;
return [QUITextPosition positionWithIndex:(direction == UITextLayoutDirectionRight ? p + offset : p - offset)];
switch (direction) {
case UITextLayoutDirectionLeft:
return [QUITextPosition positionWithIndex:p - offset];
case UITextLayoutDirectionRight:
return [QUITextPosition positionWithIndex:p + offset];
default:
// Qt doesn't support getting the position above or below the current position, so
// for those cases we just return the current position, making it a no-op.
return position;
}
}
- (UITextPosition *)positionWithinRange:(UITextRange *)range farthestInDirection:(UITextLayoutDirection)direction