From 28819b6ab639d29bf5e5897e7ac4c784771d3651 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 21 Jan 2011 13:05:55 +0000 Subject: =?UTF-8?q?=E2=80=A2=20sped=20up=20getRangeForCurrentWord=20-=20fi?= =?UTF-8?q?xes=20also=20the=20short=20interruption=20of=20the=20cursor=20b?= =?UTF-8?q?linking=20-=20for=20completion=20the=20old=20method=20is=20used?= =?UTF-8?q?,=20since=20it's=20fine-tuned=20to=20use=20it=20-=20fix=20will?= =?UTF-8?q?=20come=20soon=20-=20preparation=20for=20user-defined=20word=20?= =?UTF-8?q?symbols=20=E2=80=A2=20fixed=20issue=20for=20soft=20indent=20if?= =?UTF-8?q?=20user=20uses=20deleteForward:=20selector=20(=E2=87=A7?= =?UTF-8?q?=E2=8C=AB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPTextView.m | 4 +-- Source/SPTextViewAdditions.h | 1 + Source/SPTextViewAdditions.m | 61 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 41b5d6e4..cd6e22ff 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -606,7 +606,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSString* filter; NSString* dbName = nil; NSString* tableName = nil; - NSRange completionRange = [self getRangeForCurrentWord]; + NSRange completionRange = [self getRangeForCurrentWordForCompletion]; NSRange parseRange = completionRange; NSString* currentWord = [[self string] substringWithRange:completionRange]; NSString* prefix = @""; @@ -2445,7 +2445,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) && ![self selectedRange].length && [prefs boolForKey:SPCustomQuerySoftIndent] && [self isCaretAtIndentPositionIgnoreLineStart:YES] - && ![self isCaretAdjacentToAlphanumCharWithInsertionOf:'-']) + && [self selectedRange].location < [[self string] length] && [[self string] characterAtIndex:[self selectedRange].location] == ' ') { [self shiftSelectionLeft]; return; diff --git a/Source/SPTextViewAdditions.h b/Source/SPTextViewAdditions.h index 013d8872..b4692aee 100644 --- a/Source/SPTextViewAdditions.h +++ b/Source/SPTextViewAdditions.h @@ -25,6 +25,7 @@ @interface NSTextView (SPTextViewAdditions) - (NSRange)getRangeForCurrentWord; +- (NSRange)getRangeForCurrentWordForCompletion; - (IBAction)selectCurrentWord:(id)sender; - (IBAction)selectCurrentLine:(id)sender; diff --git a/Source/SPTextViewAdditions.m b/Source/SPTextViewAdditions.m index 750527f1..e5a15421 100644 --- a/Source/SPTextViewAdditions.m +++ b/Source/SPTextViewAdditions.m @@ -41,8 +41,69 @@ if (curRange.length) return curRange; + NSInteger curLocation = curRange.location; + NSInteger start = curLocation; + NSInteger end = curLocation; + NSUInteger strLen = [[self string] length]; + + NSMutableCharacterSet *wordCharSet = [NSMutableCharacterSet alphanumericCharacterSet]; + [wordCharSet addCharactersInString:@"_."]; + [wordCharSet removeCharactersInString:@"`"]; + + if(start) { + start--; + while([wordCharSet characterIsMember:[[self string] characterAtIndex:start]]) { + start--; + if(start < 0) break; + } + start++; + } + + while(end < strLen && [wordCharSet characterIsMember:[[self string] characterAtIndex:end]]) { + end++; + } + + return(NSMakeRange(start, end-start)); + +} +/* + * Returns the range of the current word. + * finds: [| := caret] |word wo|rd word| + * If | is in between whitespaces nothing will be selected. + */ +- (NSRange)getRangeForCurrentWordForCompletion +{ + NSRange curRange = [self selectedRange]; + + if (curRange.length) + return curRange; + NSUInteger curLocation = curRange.location; + NSMutableCharacterSet *wordCharSet = [NSMutableCharacterSet alphanumericCharacterSet]; + [wordCharSet addCharactersInString:@"_."]; + [wordCharSet removeCharactersInString:@"`"]; + + NSInteger start = curLocation; + NSInteger end = curLocation; + + if(start) { + start--; + while([wordCharSet characterIsMember:[[self string] characterAtIndex:start]]) { + start--; + if(start < 0) break; + } + start++; + } + + NSUInteger strLen = [[self string] length]; + if(end <= strLen-1) { + while(end < strLen && [wordCharSet characterIsMember:[[self string] characterAtIndex:end]]) { + end++; + } + } + return(NSMakeRange(start, end-start)); + [self moveWordLeft:self]; [self moveWordRightAndModifySelection:self]; -- cgit v1.2.3