Auto complete not working if chars typed in after quote, slash, etc

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@37069 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2013-09-11 17:55:12 +00:00
parent 624a62d838
commit 45c1de514f

View file

@ -2869,49 +2869,70 @@ Returns the ranges to which various kinds of user changes should apply.
- (NSRange) rangeForUserCompletion - (NSRange) rangeForUserCompletion
{ {
NSUInteger length, location; static NSCharacterSet *TheAplhaSet = nil; // ONLY ALPHA CHARACTERS
NSRange range, space; static NSCharacterSet *TheOtherSet = nil; // EVERYTHING ELSE...
if (TheAplhaSet == nil)
// Get the current location. {
location = [self selectedRange].location; NSMutableCharacterSet *tempSet = AUTORELEASE([[NSMutableCharacterSet alloc] init]);
[tempSet formUnionWithCharacterSet: [NSCharacterSet lowercaseLetterCharacterSet]];
// Find the first space starting from current location, backwards. [tempSet formUnionWithCharacterSet: [NSCharacterSet uppercaseLetterCharacterSet]];
space = [[self string] rangeOfCharacterFromSet: TheOtherSet = RETAIN([tempSet invertedSet]);
[NSCharacterSet whitespaceAndNewlineCharacterSet] TheAplhaSet = [tempSet copy];
options: NSBackwardsSearch }
range: NSMakeRange(0, location)];
NSRange theRange = NSMakeRange(NSNotFound, 0);
if (space.location == NSNotFound) NSString *theString = [_textStorage string];
// If we have a string typed in...
if (theString && [theString length])
{
NSRange selRange = _layoutManager->_selected_range;
if (selRange.length != 0)
{ {
// No space was found. theRange = selRange;
if (location > 0)
{
// Return the range of the whole substring.
range = NSMakeRange(0, location);
}
else
{
// There isn't word.
range = NSMakeRange(NSNotFound, 0);
}
} }
else else
{ {
length = location - space.location - 1; NSInteger length = [theString length];
NSInteger index = MAX(0, NSMaxRange(selRange)-1);
if (length > 0) unichar theChar = [theString characterAtIndex: index];
{
// Return the range of the last word. // Last character is aplha...check and set the length...
range = NSMakeRange(space.location + 1, length); if ([TheAplhaSet characterIsMember: theChar])
} {
else NSRange searchRange = NSMakeRange(0, index+1);
{
// There isn't word at the end. // Locate the first non-alpha character from the end...
range = NSMakeRange(NSNotFound, 0); theRange = [theString rangeOfCharacterFromSet: TheOtherSet options: NSBackwardsSearch range: searchRange];
} if (theRange.location != NSNotFound)
{
theRange.location += 1;
theRange.length = length - theRange.location;
}
else // Check whether we're just starting to type...
{
// Check whether there are any non-alpha characters from the beginning...
theRange = [theString rangeOfCharacterFromSet: TheAplhaSet options: 0 range: searchRange];
// This case should ONLY occur during the initial typing sequences...
if (theRange.location != 0)
{
// We SHOULD have been at location zero in the string so this
// is a problem...
NSWarnMLog(@"Unexpected completion string range processing error");
}
else
{
// There are no OTHER characters other than alpha...set the length...
theRange = NSMakeRange(0, length);
}
}
}
} }
// NSLog(@"%s:theString: %@ theRange: %@", __PRETTY_FUNCTION__, theString, NSStringFromRange(theRange));
}
return range; return theRange;
} }
- (NSArray *) rangesForUserCharacterAttributeChange - (NSArray *) rangesForUserCharacterAttributeChange