Adjust handling of selected range changes in response to text changes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19866 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
alexm 2004-08-11 23:46:37 +00:00
parent 28fca687a2
commit 706921d435
4 changed files with 50 additions and 21 deletions

View file

@ -1793,10 +1793,6 @@ This method is for user changes; see NSTextView_actions.m.
}
[self didChangeText];
/* TODO? move cursor <!> [self selectionRangeForProposedRange: ] */
[self setSelectedRange:
NSMakeRange(insertRange.location + [insertString length], 0)];
}
@ -2711,6 +2707,14 @@ afterString in order over charRange.
affinity: (NSSelectionAffinity)affinity
stillSelecting: (BOOL)stillSelectingFlag
{
/*
Note that this method might be called from the layout manager to update
the selection after the text storage has been changed. If text was deleted,
the old selected range might extend outside the current string. Also note
that this happens during the processing of the changes in the text storage.
Thus, it isn't safe to modify the text storage.
*/
/* The `official' (the last one the delegate approved of) selected
range before this one. */
NSRange oldRange;
@ -2846,6 +2850,17 @@ afterString in order over charRange.
NSMakeRange(charRange.location + charRange.length, 0)];
}
/*
If this call is caused by text being deleted, oldDisplayedRange might
extend outside the current text. We clamp it to the current length here
for safety. Redisplay might be a bit off in this case, but the text
change will cause any missing bits to be redisplayed anyway.
*/
if (oldDisplayedRange.location > length)
oldDisplayedRange.location = length;
if (NSMaxRange(oldDisplayedRange) > length)
oldDisplayedRange.length = length - oldDisplayedRange.location;
/* Try to optimize for overlapping ranges */
overlap = NSIntersectionRange (oldRange, charRange);
if (overlap.length)