mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-26 01:01:13 +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];
|
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];
|
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
|
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...
|
// Get the current location.
|
||||||
if ([TheAplhaSet characterIsMember: theChar])
|
location = selRange.location;
|
||||||
{
|
|
||||||
NSRange searchRange = NSMakeRange(0, index+1);
|
|
||||||
|
|
||||||
// Locate the first non-alpha character from the end...
|
if (location != NSNotFound && location > 0
|
||||||
theRange = [theString rangeOfCharacterFromSet: TheOtherSet options: NSBackwardsSearch range: searchRange];
|
&& [TheAplhaSet characterIsMember: [theString characterAtIndex: location - 1]])
|
||||||
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...
|
// Find the first non-alpha starting from current location, backwards.
|
||||||
if (theRange.location != 0)
|
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
|
// No non-alpha was found.
|
||||||
// is a problem...
|
if (location > 0)
|
||||||
NSWarnMLog(@"Unexpected completion string range processing error");
|
{
|
||||||
|
// Return the range of the whole substring.
|
||||||
|
range = NSMakeRange(0, location);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// There are no OTHER characters other than alpha...set the length...
|
// There isn't word.
|
||||||
theRange = NSMakeRange(0, length);
|
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
|
- (NSArray *) rangesForUserCharacterAttributeChange
|
||||||
|
|
Loading…
Reference in a new issue