mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 14:40:56 +00:00
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:
parent
d1662e45b0
commit
4d5c80b58c
1 changed files with 59 additions and 53 deletions
|
@ -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)
|
||||
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];
|
||||
else
|
||||
{
|
||||
|
||||
// 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)
|
||||
{
|
||||
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];
|
||||
if (location != NSNotFound && location > 0
|
||||
&& [TheAplhaSet characterIsMember: [theString characterAtIndex: location - 1]])
|
||||
{
|
||||
|
||||
// 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));
|
||||
}
|
||||
// Find the first non-alpha starting from current location, backwards.
|
||||
space = [[self string] rangeOfCharacterFromSet:TheOtherSet
|
||||
options: NSBackwardsSearch
|
||||
range: NSMakeRange(0, location)];
|
||||
|
||||
return theRange;
|
||||
if (space.location == NSNotFound)
|
||||
{
|
||||
// No non-alpha was found.
|
||||
if (location > 0)
|
||||
{
|
||||
// Return the range of the whole substring.
|
||||
range = NSMakeRange(0, location);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
- (NSArray *) rangesForUserCharacterAttributeChange
|
||||
|
|
Loading…
Reference in a new issue