Keep track of the original index of a sequence of moves in one dimension. Pass it to the layout manager when moving the insertion point to prevent drifting.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15956 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
alexm 2003-02-14 16:58:59 +00:00
parent 1ae44e7270
commit 174f81dd1e
4 changed files with 77 additions and 25 deletions

View file

@ -1,3 +1,19 @@
2003-02-14 17:47 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSTextView.h, Source/NSTextView.m,
Source/NSTextView_actions.m: Keep track of the original index of a
sequence of moves in one dimension. Pass it to the layout manager
when moving the insertion point to prevent drifting.
* Source/GSHorizontalTypesetter.m (-layoutLineNewParagraph:): Fix
an edge case in tab handling. Also, if tabs occur and the paragraph
style has no more tab stops, act as if there were tabs every 100
points.
* Source/NSLayoutManager.m (-characterIndexMoving:fromCharacterIndex:
originalCharacterIndex:distance:): When moving vertically, return the
index of the character nearest the target horizontally.
2003-02-13 01:01 Alexander Malmberg <alexander@malmberg.org> 2003-02-13 01:01 Alexander Malmberg <alexander@malmberg.org>
* TextConverters/RTF/rtfGrammer.y (rtfCharset): Treat unknown * TextConverters/RTF/rtfGrammer.y (rtfCharset): Treat unknown

View file

@ -185,33 +185,27 @@ therefore be stored in the NSLayoutManager to avoid problems.
need to be recomputed <eg, relayout>. */ need to be recomputed <eg, relayout>. */
NSRect _insertionPointRect; NSRect _insertionPointRect;
#if 0 /*
/* This is used when you move the insertion point up or down. The This is the character index a sequence of moves in one dimension (ie.
system remembers the horizontal position of the insertion point up/down or left/right) started at. It is passed to the layout manager
at the beginning of the process, and always tries to put the and is used when an NSTextView is deciding where to move. (Eg.
insertion point in that horizontal position on each line when you NSLayoutManager tries to maintain the original horizontal position when
go up or down. The memory of the horizontal position is changed moving up/down.)
as soon as you do something different from moving the cursor */
up/down. */ unsigned int _originalInsertionPointCharacterIndex;
/* TODO: cursor movement needs to be worked out. The current methods
aren't good enough (eg. in a vertical layout, the original y position
should be preserved when moving left/right, but the original x position
is meaningless). A position (in the text container coordinate system)
based system won't work when moving through ligatures. A character based
system is better. A _originalCharacterIndex here should solve the problems;
a method:
-(unsigned int) characterIndexMoving: (int)direction /*
from: (unsigned int)currentCharIndex 0=no information (_originalInsertionPointCharacterIndex undefined)
original: (unsigned int)originalCharIndex 1=horizontal
2=vertical
*/
int _currentInsertionPointMovementDirection;
should be able to give proper behavior in all cases. /*
TODO:
Need to figure out what "proper behavior" is when moving between two Still need to figure out what "proper behavior" is when moving between two
NSTextView:s, though. NSTextView:s, though.
*/ */
unsigned int _originalCharIndex;
#endif
} }

View file

@ -23,6 +23,9 @@
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr> Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
Date: September 2002 Date: September 2002
Extensive reworking: Alexander Malmberg <alexander@malmberg.org>
Date: December 2002 - February 2003
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@ -711,6 +714,8 @@ to this method from the text container or layout manager.
_layoutManager->_selected_range = NSMakeRange(0,0); _layoutManager->_selected_range = NSMakeRange(0,0);
} }
_currentInsertionPointMovementDirection = 0;
[self _updateMultipleTextViews]; [self _updateMultipleTextViews];
} }
@ -2610,6 +2615,14 @@ afterString in order over charRange.
/* Set the new selected range */ /* Set the new selected range */
_layoutManager->_selected_range = charRange; _layoutManager->_selected_range = charRange;
/* Clear the remembered position and direction for insertion point
movement.
Note that we must _not_ clear the index. Many movement actions will
reset the direction to a valid value, and they assume that the index
remains unchanged here. */
_currentInsertionPointMovementDirection = 0;
/* TODO: when and if to restart timer <and where to stop it before> */ /* TODO: when and if to restart timer <and where to stop it before> */
[self updateInsertionPointStateAndRestartTimer: !stillSelectingFlag]; [self updateInsertionPointStateAndRestartTimer: !stillSelectingFlag];

View file

@ -22,6 +22,9 @@
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr> Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
Date: September 2002 Date: September 2002
Extensive reworking: Alexander Malmberg <alexander@malmberg.org>
Date: December 2002 - February 2003
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@ -723,14 +726,40 @@ added to the selection (1,3).
select: (BOOL)select select: (BOOL)select
{ {
unsigned int cindex; unsigned int cindex;
int new_direction;
if (direction == GSInsertionPointMoveUp ||
direction == GSInsertionPointMoveDown)
{
new_direction = 2;
}
else if (direction == GSInsertionPointMoveLeft ||
direction == GSInsertionPointMoveRight)
{
new_direction = 1;
}
else
{
new_direction = 0;
}
cindex = [self _movementOrigin]; cindex = [self _movementOrigin];
if (new_direction != _currentInsertionPointMovementDirection ||
!new_direction)
{
_originalInsertionPointCharacterIndex = cindex;
}
cindex = [_layoutManager characterIndexMoving: direction cindex = [_layoutManager characterIndexMoving: direction
fromCharacterIndex: cindex fromCharacterIndex: cindex
originalCharacterIndex: cindex /* TODO */ originalCharacterIndex: _originalInsertionPointCharacterIndex
distance: distance]; distance: distance];
[self _moveTo: cindex [self _moveTo: cindex
select: select]; select: select];
/* Setting the selected range will clear out the current direction, but
not the index. Thus, we always set the direction here. */
_currentInsertionPointMovementDirection = new_direction;
} }