mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 12:50:55 +00:00
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:
parent
624a62d838
commit
45c1de514f
1 changed files with 59 additions and 38 deletions
|
@ -2869,49 +2869,70 @@ Returns the ranges to which various kinds of user changes should apply.
|
|||
|
||||
- (NSRange) rangeForUserCompletion
|
||||
{
|
||||
NSUInteger length, location;
|
||||
NSRange range, space;
|
||||
static NSCharacterSet *TheAplhaSet = nil; // ONLY ALPHA CHARACTERS
|
||||
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.
|
||||
location = [self selectedRange].location;
|
||||
NSRange theRange = NSMakeRange(NSNotFound, 0);
|
||||
NSString *theString = [_textStorage string];
|
||||
|
||||
// Find the first space starting from current location, backwards.
|
||||
space = [[self string] rangeOfCharacterFromSet:
|
||||
[NSCharacterSet whitespaceAndNewlineCharacterSet]
|
||||
options: NSBackwardsSearch
|
||||
range: NSMakeRange(0, location)];
|
||||
|
||||
if (space.location == NSNotFound)
|
||||
// If we have a string typed in...
|
||||
if (theString && [theString length])
|
||||
{
|
||||
NSRange selRange = _layoutManager->_selected_range;
|
||||
if (selRange.length != 0)
|
||||
{
|
||||
// No space 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);
|
||||
}
|
||||
theRange = selRange;
|
||||
}
|
||||
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)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
// Last character is aplha...check and set the length...
|
||||
if ([TheAplhaSet characterIsMember: theChar])
|
||||
{
|
||||
NSRange searchRange = NSMakeRange(0, index+1);
|
||||
|
||||
// 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];
|
||||
|
||||
// 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
|
||||
|
|
Loading…
Reference in a new issue