From 37e7a952eebd25515bb3ee9d85898a5a984f9d21 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 16 Aug 2010 15:15:27 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0auto-completion=20in=20Query=20Editor=20?= =?UTF-8?q?now=20detects=20whether=20the=20caret=20is=20inside=20quotes=20?= =?UTF-8?q?or=20not=20in=20order=20to=20come=20up=20with=20the=20correct?= =?UTF-8?q?=20suggestions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPNarrowDownCompletion.m | 6 ++++++ Source/SPTextView.m | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index 508df857..c34bce52 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -612,6 +612,12 @@ if([mutablePrefix length] > 0) { if(dictMode) { + NSPredicate* predicate; + if(caseSensitive) + predicate = [NSPredicate predicateWithFormat:@"match BEGINSWITH %@ OR (match == NULL AND display BEGINSWITH %@)", [self filterString], [self filterString]]; + else + predicate = [NSPredicate predicateWithFormat:@"match BEGINSWITH[c] %@ OR (match == NULL AND display BEGINSWITH[c] %@)", [self filterString], [self filterString]]; + [newFiltered addObjectsFromArray:[suggestions filteredArrayUsingPredicate:predicate]]; for(id w in [[NSSpellChecker sharedSpellChecker] completionsForPartialWordRange:NSMakeRange(0,[[self filterString] length]) inString:[self filterString] language:nil inSpellDocumentWithTag:0]) [newFiltered addObject:[NSDictionary dictionaryWithObjectsAndKeys:w, @"display", nil]]; } else { diff --git a/Source/SPTextView.m b/Source/SPTextView.m index 9501992a..32547627 100644 --- a/Source/SPTextView.m +++ b/Source/SPTextView.m @@ -549,8 +549,15 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // Suppress auto-completion if the window isn't active anymore if ([[NSApp keyWindow] firstResponder] != self) return; + BOOL useSpellChecker = NO; + + // Check if caret is inside a quote to auto-complete by using spellChecker + NSColor *currentCharColor = [[self textStorage] attribute:NSForegroundColorAttributeName atIndex:r.location-1 effectiveRange:nil]; + if(currentCharColor && currentCharColor == quoteColor) + useSpellChecker = YES; + // Trigger the completion - [self doCompletionByUsingSpellChecker:NO fuzzyMode:NO autoCompleteMode:YES]; + [self doCompletionByUsingSpellChecker:useSpellChecker fuzzyMode:NO autoCompleteMode:YES]; } } -- cgit v1.2.3