diff --git a/ChangeLog b/ChangeLog index 81f1a8176..93bbea0d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2000-12-27 Richard Frith-Macdonald + + * Source/NSAttributedString.m: ([-doubleClickAtIndex:]), + Fixed infinite loop. Added code to cope with double click on the + space between words. + * Source/NSTextView.m: ([-selectionRangeForProposedRange:granularity]) + Re-implemented word selection using ([-doubleClickAtIndex:]) + ([-mouseDown:]) creatre proposed range for selection by merging old + selectin range with new location. + 2000-12-24 Fred Kiefer * Headers/gnustep/gui/NSButton.h: diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 633daa8a3..0d6d7c187 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -266,6 +266,21 @@ static inline void cache_init () format: @"RangeError in method -doubleClickAtIndex:"]; } + /* + * If the location lies between words, a double click selects only + * the character actually clicked on. + */ + if ([wordBreakCSet characterIsMember: [str characterAtIndex: location]]) + { + if (location == 0 || location == length - 1 + || [str characterAtIndex: location] != '\'' + || ! [wordCSet characterIsMember: [str characterAtIndex: location - 1]] + || ! [wordCSet characterIsMember: [str characterAtIndex: location + 1]]) + { + return NSMakeRange(location, 1); + } + } + scanRange = NSMakeRange (0, location); startRange = [str rangeOfCharacterFromSet: wordBreakCSet options: NSBackwardsSearch|NSLiteralSearch @@ -299,7 +314,7 @@ static inline void cache_init () { location = endRange.location + 1; scanRange = NSMakeRange (location, length - location); - startRange = [str rangeOfCharacterFromSet: wordBreakCSet + endRange = [str rangeOfCharacterFromSet: wordBreakCSet options: NSLiteralSearch range: scanRange]; } diff --git a/Source/NSTextView.m b/Source/NSTextView.m index dc9429c61..9c2008aaa 100644 --- a/Source/NSTextView.m +++ b/Source/NSTextView.m @@ -1975,6 +1975,7 @@ afterString in order over charRange. */ /* Compute the new selection */ startIndex = [self characterIndexForPoint: startPoint]; proposedRange = NSMakeRange (startIndex, 0); + proposedRange = NSUnionRange (_selected_range, proposedRange); proposedRange = [self selectionRangeForProposedRange: proposedRange granularity: granularity]; /* Merge it with the old one */ @@ -2591,41 +2592,21 @@ container, returning the modified location. */ switch (granul) { case NSSelectByWord: - /* FIXME: The following code (or the routines it calls) does the - wrong thing when you double-click on the space between two - words */ - if ((proposedCharRange.location + 1) < length) + index = proposedCharRange.location; + if (index >= length) { - index = [_textStorage nextWordFromIndex: - (proposedCharRange.location + 1) - forward: NO]; + index = length - 1; } - else + newRange = [_textStorage doubleClickAtIndex: index]; + if (proposedCharRange.length > 1) { - /* Exception: end of text */ - index = [_textStorage nextWordFromIndex: proposedCharRange.location - forward: NO]; - } - newRange.location = index; - index = [_textStorage nextWordFromIndex: NSMaxRange (proposedCharRange) - forward: YES]; - if (index <= newRange.location) - { - newRange.length = 0; - } - else - { - if (index == length) + index = NSMaxRange(proposedCharRange) - 1; + if (index >= length) { - /* We are at the end of text ! */ - newRange.length = index - newRange.location; - } - else - { - /* FIXME: The following will not work if there is more than a - single character between the two words ! */ - newRange.length = index - 1 - newRange.location; + index = length - 1; } + aRange = [_textStorage doubleClickAtIndex: index]; + newRange = NSUnionRange(newRange, aRange); } return newRange;