From 2735e15bf5d4b3a976435ebb29ca9073de0e5071 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 4 Jan 2015 03:57:26 +0100 Subject: Formalize [x release], x = nil; convention Take this commit as a proposal to formalize our existing "[x release], x = nil;" convention by introducing a macro for it. Feel free to revert this commit if you see issues with the approch or implementation. --- Source/SPGotoDatabaseController.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/SPGotoDatabaseController.m') diff --git a/Source/SPGotoDatabaseController.m b/Source/SPGotoDatabaseController.m index 3f9a4730..5e8a4fb2 100644 --- a/Source/SPGotoDatabaseController.m +++ b/Source/SPGotoDatabaseController.m @@ -265,8 +265,8 @@ - (void)dealloc { - [unfilteredList release], unfilteredList = nil; - [filteredList release], filteredList = nil; + SPClear(unfilteredList); + SPClear(filteredList); [super dealloc]; } -- cgit v1.2.3 From a9f5656e9649cf67bae7c6362bb5366f9dde3b44 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 7 Mar 2015 22:20:41 +0100 Subject: Fuzzy search for "Go to database" --- Source/SPGotoDatabaseController.m | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'Source/SPGotoDatabaseController.m') diff --git a/Source/SPGotoDatabaseController.m b/Source/SPGotoDatabaseController.m index 5e8a4fb2..23b43ee2 100644 --- a/Source/SPGotoDatabaseController.m +++ b/Source/SPGotoDatabaseController.m @@ -185,21 +185,27 @@ nil]; for (NSString *db in unfilteredList) { - // Let's just assume it is in the users interest (most of the time) for searches to be CI. - NSRange match = [db rangeOfString:filter options:NSCaseInsensitiveSearch]; - - if (match.location == NSNotFound) continue; - + + NSArray *matches = nil; + BOOL hasMatch = [db nonConsecutivelySearchString:filter matchingRanges:&matches]; + + if(!hasMatch) continue; + // Should we check for exact match AND have not yet found one? if (exactMatch && !*exactMatch) { - if (match.location == 0 && match.length == [db length]) { - *exactMatch = YES; + if([matches count] == 1) { + NSRange match = [(NSValue *)[matches objectAtIndex:0] rangeValue]; + if (match.location == 0 && match.length == [db length]) { + *exactMatch = YES; + } } } NSMutableAttributedString *attrMatch = [[NSMutableAttributedString alloc] initWithString:db]; - [attrMatch setAttributes:attrs range:match]; + for (NSValue *matchValue in matches) { + [attrMatch setAttributes:attrs range:[matchValue rangeValue]]; + } [filteredList addObject:[attrMatch autorelease]]; } -- cgit v1.2.3