From 78fc19a490062f3693750fc04486cc4ff3a62d64 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 11 Feb 2003 15:39:49 +0000 Subject: [PATCH] (-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 --- Source/NSTextStorage.m | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Source/NSTextStorage.m b/Source/NSTextStorage.m index d4333d2c0..1434e2528 100644 --- a/Source/NSTextStorage.m +++ b/Source/NSTextStorage.m @@ -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.