--- NSTextView.m.orig Tue Jul 2 18:32:44 2002 +++ NSTextView.m Tue Jul 9 14:34:40 2002 @@ -1334,6 +1334,7 @@ displayed selection could have been a temporary selection, different from the last official one: */ NSRange oldDisplayedRange = _selected_range; + int textStorageLength = 0; if (flag == YES) { @@ -1375,6 +1376,30 @@ /* FIXME: when and if to restart timer */ [self updateInsertionPointStateAndRestartTimer: !flag]; + // Unhighlighting old selected range + textStorageLength = [_textStorage length]; + if ( oldRange.length && (NSMaxRange(oldRange) <= textStorageLength) ) + { + if (oldDisplayedRange.length) + { + [_textStorage removeAttribute: NSBackgroundColorAttributeName + range: oldDisplayedRange]; + } + } + else if ( oldRange.length && (NSMaxRange(oldRange) >= textStorageLength) ) + { + // leaving text smaller then old range(deleted range) + [_textStorage removeAttribute: NSBackgroundColorAttributeName + range: NSMakeRange(0, textStorageLength)]; + } + else if ( textStorageLength == 1 ) + { + // Should not enter here: deleteForward calls us berfore deleting oldRange + // selected text + [_textStorage removeAttribute: NSBackgroundColorAttributeName + range: NSMakeRange(0, 1)]; + } + if (flag == NO) { [self updateFontPanel]; @@ -2403,14 +2428,14 @@ return; } + /* The new selected range is just the insertion point at the beginning + of deleted range */ + [self setSelectedRange: NSMakeRange (range.location, 0)]; + [_textStorage beginEditing]; [_textStorage deleteCharactersInRange: range]; [_textStorage endEditing]; [self didChangeText]; - - /* The new selected range is just the insertion point at the beginning - of deleted range */ - [self setSelectedRange: NSMakeRange (range.location, 0)]; } - (void) deleteBackward: (id)sender