Fixed a bug introduced in rev #37069 where autocomplete was no longer working unless we were at the beginning or end of a text.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@37179 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Frank Le Grand 2013-10-01 15:41:37 +00:00
parent d1662e45b0
commit 4d5c80b58c

View file

@ -2880,59 +2880,65 @@ Returns the ranges to which various kinds of user changes should apply.
TheAplhaSet = [tempSet copy];
}
NSRange theRange = NSMakeRange(NSNotFound, 0);
NSUInteger length, location;
NSRange space; // The range of the first space or non-alpha character.
NSRange range = NSMakeRange(NSNotFound, 0);
NSRange selRange = [self selectedRange];
NSString *theString = [_textStorage string];
// If we have a string typed in...
if (theString && [theString length])
{
NSRange selRange = _layoutManager->_selected_range;
if (selRange.length != 0)
{
theRange = selRange;
range = selRange;
}
else
{
NSInteger length = [theString length];
NSInteger index = MAX(0, NSMaxRange(selRange)-1);
unichar theChar = [theString characterAtIndex: index];
// Last character is aplha...check and set the length...
if ([TheAplhaSet characterIsMember: theChar])
{
NSRange searchRange = NSMakeRange(0, index+1);
// Get the current location.
location = selRange.location;
// Locate the first non-alpha character from the end...
theRange = [theString rangeOfCharacterFromSet: TheOtherSet options: NSBackwardsSearch range: searchRange];
if (theRange.location != NSNotFound)
if (location != NSNotFound && location > 0
&& [TheAplhaSet characterIsMember: [theString characterAtIndex: location - 1]])
{
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)
// Find the first non-alpha starting from current location, backwards.
space = [[self string] rangeOfCharacterFromSet:TheOtherSet
options: NSBackwardsSearch
range: NSMakeRange(0, location)];
if (space.location == NSNotFound)
{
// We SHOULD have been at location zero in the string so this
// is a problem...
NSWarnMLog(@"Unexpected completion string range processing error");
// No non-alpha was found.
if (location > 0)
{
// Return the range of the whole substring.
range = NSMakeRange(0, location);
}
else
{
// There are no OTHER characters other than alpha...set the length...
theRange = NSMakeRange(0, length);
// There isn't word.
range = NSMakeRange(NSNotFound, 0);
}
}
else
{
length = location - space.location - 1;
if (length > 0)
{
// Return the range of the last word.
range = NSMakeRange(space.location + 1, length);
}
else
{
// There isn't word at the end.
range = NSMakeRange(NSNotFound, 0);
}
}
}
}
// NSLog(@"%s:theString: %@ theRange: %@", __PRETTY_FUNCTION__, theString, NSStringFromRange(theRange));
}
return theRange;
return range;
}
- (NSArray *) rangesForUserCharacterAttributeChange