From 748b8d279907bd3ce5c1b0dbd33edaa296ea2bb5 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 22 Jan 2010 13:23:29 +0000 Subject: =?UTF-8?q?=E2=80=A2=20bound=20Custom=20Query=20gear=20menu=20item?= =?UTF-8?q?=20"Completion=20List"=20=20(CTRL=20key=20is=20recognized)=20?= =?UTF-8?q?=E2=80=A2=20use=20regexp=20to=20get=20a=20list=20of=20current?= =?UTF-8?q?=20words=20and=20reduced=20that=20method=20to=20invoked=20if=20?= =?UTF-8?q?the=20text=20buffer=20is=20less=20than=2060KB=20to=20speed=20up?= =?UTF-8?q?=20the=20completion=20(it's=20more=20likely=20that=20the=20user?= =?UTF-8?q?=20wants=20to=20complete=20a=20sql=20related=20term)=20?= =?UTF-8?q?=E2=80=A2=20some=20code=20cosmetics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 24 +++++++++++------------- Source/CustomQuery.m | 5 ++++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/CMTextView.m b/Source/CMTextView.m index b64c07a0..4b42d009 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -169,13 +169,11 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // If caret is not inside backticks add keywords and all words coming from the view. if(!dbBrowseMode) { - // Only parse for words if text size is less than 6MB - if([[self string] length] && [[self string] length]<6000000) + // Only parse for words if text size is less than 60kB + if([[self string] length] && [[self string] length]<60000) { - NSCharacterSet *separators = [NSCharacterSet characterSetWithCharactersInString:@" \t\r\n,()[]{}\"'`-!;=+|?:~@."]; - NSMutableArray *uniqueArray = [NSMutableArray array]; - [uniqueArray addObjectsFromArray:[[NSSet setWithArray:[[self string] componentsSeparatedByCharactersInSet:separators]] allObjects]]; + [uniqueArray addObjectsFromArray:[NSSet setWithArray:[[self string] componentsMatchedByRegex:@"\\w+"]]]; // Remove current word from list [uniqueArray removeObject:currentWord]; @@ -397,6 +395,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // No completion for a selection (yet?) and if caret positiopn == 0 if([self selectedRange].length > 0 || ![self selectedRange].location) return; + [self breakUndoCoalescing]; + NSInteger caretPos = [self selectedRange].location; BOOL caretMovedLeft = NO; @@ -431,6 +431,11 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSInteger backtickMode = 0; // 0 none, 1 rigth only, 2 left only, 3 both BOOL caseInsensitive = YES; + // Remove that attribute to suppress auto-uppercasing of certain keyword combinations + if(![self selectedRange].length && [self selectedRange].location) + [[self textStorage] removeAttribute:kSQLkeyword range:completionRange]; + + if(!isDictMode) { // Parse for leading db.table.field infos @@ -822,22 +827,15 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) unichar insertedCharacter = [characters characterAtIndex:0]; long curFlags = ([theEvent modifierFlags] & allFlags); - if ([theEvent keyCode] == 53){ // ESC key for internal completion - [self breakUndoCoalescing]; + if ([theEvent keyCode] == 53 && [self isEditable]){ // ESC key for internal completion if(curFlags==(NSControlKeyMask)) [self doCompletionByUsingSpellChecker:NO fuzzyMode:YES]; else [self doCompletionByUsingSpellChecker:NO fuzzyMode:NO]; - // Remove that attribute to suppress auto-uppercasing of certain keyword combinations - if(![self selectedRange].length && [self selectedRange].location) - [[self textStorage] removeAttribute:kSQLkeyword range:[self getRangeForCurrentWord]]; return; } if (insertedCharacter == NSF5FunctionKey){ // F5 for completion based on spell checker [self doCompletionByUsingSpellChecker:YES fuzzyMode:NO]; - // Remove that attribute to suppress auto-uppercasing of certain keyword combinations - if(![self selectedRange].length && [self selectedRange].location) - [[self textStorage] removeAttribute:kSQLkeyword range:[self getRangeForCurrentWord]]; return; } diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 62deb15d..b536491b 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -283,7 +283,10 @@ // "Completion List" menu item - used to autocomplete. Uses a different shortcut to avoid the menu button flickering // on normal autocomplete usage. if (sender == completionListMenuItem) { - [textView complete:self]; + if([[NSApp currentEvent] modifierFlags] & (NSControlKeyMask)) + [textView doCompletionByUsingSpellChecker:NO fuzzyMode:YES]; + else + [textView doCompletionByUsingSpellChecker:NO fuzzyMode:NO]; } // "Editor font..." menu item to bring up the font panel -- cgit v1.2.3