(-processEditing): Make sure we always give a valid range and delta to the layout managers.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15936 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-02-11 15:39:49 +00:00
parent ea14bf8170
commit 413dec23ee

View file

@ -186,6 +186,7 @@ static NSNotificationCenter *nc = nil;
- (void) processEditing
{
NSRange r;
int original_delta;
int i;
unsigned length;
@ -201,6 +202,7 @@ static NSNotificationCenter *nc = nil;
/* Very important: we save the current _editedRange */
r = _editedRange;
original_delta = _editedDelta;
length = [self length];
// Multiple adds at the end might give a too long result
if (NSMaxRange(r) > length)
@ -221,6 +223,31 @@ static NSNotificationCenter *nc = nil;
object: self];
_editCount--;
/*
The attribute fixes might have added or removed characters. We must make
sure that range and delta we give to the layout managers is valid.
*/
if (original_delta != _editedDelta)
{
if (_editedDelta - original_delta > 0)
{
r.length += _editedDelta - original_delta;
}
else
{
if (original_delta - _editedDelta > r.length)
{
r.length = 0;
if (r.location > [self length])
r.location = [self length];
}
else
{
r.length += _editedDelta - original_delta;
}
}
}
/*
* Calls textStorage:edited:range:changeInLength:invalidatedRange: for
* every layoutManager.