Double clicking on a white space character also selects the

surrounding white space as on OS X.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27131 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2008-11-25 21:46:23 +00:00
parent d1514c3ce1
commit 28b86a0bae
2 changed files with 38 additions and 6 deletions

View file

@ -1,3 +1,9 @@
2008-11-25 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSAttributedString.m (-doubleClickAtIndex:): Double
clicking on a white space character also selects the surrounding
white space as on OS X.
2008-11-24 Wolfgang Lux <wolfgang.lux@gmail.com>
* Headers/AppKit/NSTextView.h: Rename and change types of

View file

@ -62,6 +62,10 @@ static Class stringClass = nil;
static NSCharacterSet *wordBreakCSet = nil;
/* A character set containing characters that are legal within words. */
static NSCharacterSet *wordCSet = nil;
/* Character sets containing characters that are white space and
not white space */
static NSCharacterSet *whiteCSet = nil;
static NSCharacterSet *nonWhiteCSet = nil;
/* A String containing the attachment character */
static NSString *attachmentString = nil;
@ -94,6 +98,10 @@ static void cache_init_real(void)
/* Initializes wordCSet */
wordCSet = [[wordBreakCSet invertedSet] copy];
/* Initializes white space and non-white space character sets */
whiteCSet = [[NSCharacterSet whitespaceCharacterSet] copy];
nonWhiteCSet = [[whiteCSet invertedSet] copy];
/* Initializes attachmentString */
attachmentString = [stringClass stringWithCharacters: &ch length: 1];
@ -403,6 +411,7 @@ static Class converter_class(NSString *format, BOOL producer)
NSRange scanRange;
NSRange startRange;
NSRange endRange;
NSCharacterSet *breakCSet;
cache_init ();
@ -413,10 +422,15 @@ static Class converter_class(NSString *format, BOOL producer)
}
/*
* If the location lies between words, a double click selects only
* the character actually clicked on.
* Double clicking on a white space character selects all surrounding
* white space. Otherwise, if the location lies between words, a double
* click selects only the character actually clicked on.
*/
if ([wordBreakCSet characterIsMember: [str characterAtIndex: location]])
if ([whiteCSet characterIsMember: [str characterAtIndex: location]])
{
breakCSet = nonWhiteCSet;
}
else if ([wordBreakCSet characterIsMember: [str characterAtIndex: location]])
{
if (location == 0 || location == length - 1
|| [str characterAtIndex: location] != '\''
@ -425,13 +439,21 @@ static Class converter_class(NSString *format, BOOL producer)
{
return NSMakeRange(location, 1);
}
breakCSet = wordBreakCSet;
}
else
{
breakCSet = wordBreakCSet;
}
scanRange = NSMakeRange (0, location);
startRange = [str rangeOfCharacterFromSet: wordBreakCSet
startRange = [str rangeOfCharacterFromSet: breakCSet
options: NSBackwardsSearch|NSLiteralSearch
range: scanRange];
/*
* Don't treat single quotes embedded within a word as break characters.
* Note: The loop condition is always false when breakCSet==nonWhiteSetCSet.
*/
while (startRange.length > 0
&& startRange.location > 0 && startRange.location < length - 1
&& [str characterAtIndex: startRange.location] == '\''
@ -447,9 +469,13 @@ static Class converter_class(NSString *format, BOOL producer)
}
scanRange = NSMakeRange (location, length - location);
endRange = [str rangeOfCharacterFromSet: wordBreakCSet
endRange = [str rangeOfCharacterFromSet: breakCSet
options: NSLiteralSearch
range: scanRange];
/*
* Don't treat single quotes embedded within a word as break characters.
* Note: The loop condition is always false when breakCSet==nonWhiteSetCSet.
*/
while (endRange.length > 0
&& endRange.location > 0 && endRange.location < length - 1
&& [str characterAtIndex: endRange.location] == '\''