mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-24 06:28:54 +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
6d1c78032a
commit
c56d68453d
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 ||
|
||||
direction == GSInsertionPointMoveDown)
|
||||
{
|
||||
NSRect orig_rect;
|
||||
NSRect orig_rect, prev_rect;
|
||||
int orig_tc;
|
||||
float target;
|
||||
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. */
|
||||
new_rect = [self _insertionPointRectForCharacterIndex: new
|
||||
textContainer: &new_tc];
|
||||
while (new < length)
|
||||
{
|
||||
prev_rect = new_rect;
|
||||
new_rect = [self _insertionPointRectForCharacterIndex: new + 1
|
||||
textContainer: &new_tc];
|
||||
if (new_tc != from_tc)
|
||||
break;
|
||||
if (new_rect.origin.y != lf->rect.origin.y)
|
||||
break;
|
||||
new++;
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue