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)
{
NSMutableCharacterSet *tempSet = AUTORELEASE([[NSMutableCharacterSet alloc] init]);
[tempSet formUnionWithCharacterSet: [NSCharacterSet lowercaseLetterCharacterSet]];
[tempSet formUnionWithCharacterSet: [NSCharacterSet uppercaseLetterCharacterSet]];
TheOtherSet = RETAIN([tempSet invertedSet]);
TheAplhaSet = [tempSet copy];
}
// Get the current location. NSRange theRange = NSMakeRange(NSNotFound, 0);
location = [self selectedRange].location; NSString *theString = [_textStorage string];
// Find the first space starting from current location, backwards. // If we have a string typed in...
space = [[self string] rangeOfCharacterFromSet: if (theString && [theString length])
[NSCharacterSet whitespaceAndNewlineCharacterSet] {
options: NSBackwardsSearch NSRange selRange = _layoutManager->_selected_range;
range: NSMakeRange(0, location)]; if (selRange.length != 0)
if (space.location == NSNotFound)
{ {
// 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);
unichar theChar = [theString characterAtIndex: index];
if (length > 0) // Last character is aplha...check and set the length...
{ if ([TheAplhaSet characterIsMember: theChar])
// Return the range of the last word. {
range = NSMakeRange(space.location + 1, length); NSRange searchRange = NSMakeRange(0, index+1);
}
else // Locate the first non-alpha character from the end...
{ theRange = [theString rangeOfCharacterFromSet: TheOtherSet options: NSBackwardsSearch range: searchRange];
// There isn't word at the end. if (theRange.location != NSNotFound)
range = NSMakeRange(NSNotFound, 0); {
} 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