From cc40f75fbe1896eb69d84a8f00ed20b6bb70bd28 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 5 Feb 2010 21:23:20 +0000 Subject: =?UTF-8?q?=E2=80=A2=20improved=20completion=20behaviour=20of=20su?= =?UTF-8?q?ggestions=20containing=20spaces;=20a=20second=20space=20will=20?= =?UTF-8?q?cancel=20the=20list=20to=20allow=20a=20more=20natural=20typing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPNarrowDownCompletion.h | 1 + Source/SPNarrowDownCompletion.m | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPNarrowDownCompletion.h b/Source/SPNarrowDownCompletion.h index de4e7a06..96558b9d 100644 --- a/Source/SPNarrowDownCompletion.h +++ b/Source/SPNarrowDownCompletion.h @@ -58,6 +58,7 @@ id theView; NSInteger maxWindowWidth; + NSInteger spaceCounter; NSMutableCharacterSet* textualInputCharacters; } diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index a48aa204..3b108de6 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -109,6 +109,7 @@ textualInputCharacters = [[NSMutableCharacterSet alphanumericCharacterSet] retain]; caseSensitive = YES; filtered = nil; + spaceCounter = 0; tableFont = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:SPCustomQueryEditorFont]]; [self setupInterface]; @@ -369,12 +370,13 @@ - (void)checkSpaceForAllowedCharacter { [textualInputCharacters removeCharactersInString:@" "]; - for(id w in filtered){ - if([[w objectForKey:@"match"] ?: [w objectForKey:@"display"] rangeOfString:@" "].length) { - [textualInputCharacters addCharactersInString:@" "]; - break; + if(spaceCounter < 1) + for(id w in filtered){ + if([[w objectForKey:@"match"] ?: [w objectForKey:@"display"] rangeOfString:@" "].length) { + [textualInputCharacters addCharactersInString:@" "]; + break; + } } - } } // ==================== @@ -561,6 +563,7 @@ if([mutablePrefix length] == 0 || commaInsertionMode) break; + spaceCounter = 0; [mutablePrefix deleteCharactersInRange:NSMakeRange([mutablePrefix length]-1, 1)]; theCharRange.length--; theParseRange.length--; @@ -572,12 +575,15 @@ if(commaInsertionMode) break; + if([event keyCode] == 49) // space + spaceCounter++; [mutablePrefix appendString:[event characters]]; theCharRange.length++; theParseRange.length++; [self filter]; [self insertCommonPrefix]; + } else { -- cgit v1.2.3