mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 19:50:48 +00:00
When moving vertically, return the index of the character nearest the target horizontally.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15958 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bf716a59d2
commit
becd665c33
1 changed files with 15 additions and 3 deletions
|
@ -809,7 +809,7 @@ has the same y origin and height as the line frag rect it is in.
|
||||||
if (direction == GSInsertionPointMoveUp ||
|
if (direction == GSInsertionPointMoveUp ||
|
||||||
direction == GSInsertionPointMoveDown)
|
direction == GSInsertionPointMoveDown)
|
||||||
{
|
{
|
||||||
NSRect orig_rect;
|
NSRect orig_rect, prev_rect;
|
||||||
int orig_tc;
|
int orig_tc;
|
||||||
float target;
|
float target;
|
||||||
textcontainer_t *tc;
|
textcontainer_t *tc;
|
||||||
|
@ -902,17 +902,29 @@ has the same y origin and height as the line frag rect it is in.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now find the target character in the line. */
|
/* Now find the target character in the line. */
|
||||||
|
new_rect = [self _insertionPointRectForCharacterIndex: new
|
||||||
|
textContainer: &new_tc];
|
||||||
while (new < length)
|
while (new < length)
|
||||||
{
|
{
|
||||||
|
prev_rect = new_rect;
|
||||||
new_rect = [self _insertionPointRectForCharacterIndex: new + 1
|
new_rect = [self _insertionPointRectForCharacterIndex: new + 1
|
||||||
textContainer: &new_tc];
|
textContainer: &new_tc];
|
||||||
if (new_tc != from_tc)
|
if (new_tc != from_tc)
|
||||||
break;
|
break;
|
||||||
if (new_rect.origin.y != lf->rect.origin.y)
|
if (new_rect.origin.y != lf->rect.origin.y)
|
||||||
break;
|
break;
|
||||||
new++;
|
|
||||||
if (NSMinX(new_rect) >= target)
|
if (NSMinX(new_rect) >= target)
|
||||||
break;
|
{
|
||||||
|
/*
|
||||||
|
'new+1' is beyond 'target', so either 'new' or 'new+1' is the
|
||||||
|
character we want. Pick the closest one. (Note that 'new' might
|
||||||
|
also be beyond 'target'.)
|
||||||
|
*/
|
||||||
|
if (fabs(NSMinX(new_rect) - target) < fabs(NSMinX(prev_rect) - target))
|
||||||
|
new++;
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
new++;
|
||||||
}
|
}
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue