Selection fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8450 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-12-27 06:28:29 +00:00
parent 7b3c4722a1
commit 7fdaabcdde
3 changed files with 37 additions and 31 deletions

View file

@ -1,3 +1,13 @@
2000-12-27 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <FredKiefer@gmx.de>
* Headers/gnustep/gui/NSButton.h:

View file

@ -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];
}

View file

@ -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;