diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMTextView.m | 5 | ||||
-rw-r--r-- | Source/CustomQuery.h | 1 | ||||
-rw-r--r-- | Source/CustomQuery.m | 20 |
3 files changed, 17 insertions, 9 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 27fb0dab..3720a521 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -531,11 +531,6 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [self makeTextSizeSmaller]; return; } - if([charactersIgnMod isEqualToString:@"/"]) - { - [[[[self window] delegate] valueForKeyPath:@"customQueryInstance"] commentOutQuery]; - return; - } } // Only process for character autopairing if autopairing is enabled and a single character is being added. diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 56f56f0d..9d6ea2df 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -63,6 +63,7 @@ IBOutlet NSMenuItem *autopairMenuItem; IBOutlet NSMenuItem *autohelpMenuItem; IBOutlet NSMenuItem *autouppercaseKeywordsMenuItem; + IBOutlet NSMenuItem *commentCurrentQueryOrSelectionMenuItem; IBOutlet NSWindow *helpWebViewWindow; IBOutlet WebView *helpWebView; diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 00834f80..59be27f8 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -212,6 +212,12 @@ [textView shiftSelectionLeft]; } + // "Comment Current Query/Selection" menu item - Add or remove "-- " for each line + // in the current query or selection + if (sender == commentCurrentQueryOrSelectionMenuItem) { + [self commentOutQuery]; + } + // "Completion List" menu item - used to autocomplete. Uses a different shortcut to avoid the menu button flickering // on normal autocomplete usage. if (sender == completionListMenuItem) { @@ -927,6 +933,9 @@ [textView setSelectedRange:currentQueryRange]; } +/* + * Add or remove "-- " for each line in the current query or selection + */ - (void)commentOutQuery { @@ -945,11 +954,14 @@ workingRange = currentQueryRange; NSMutableString *n = [NSMutableString string]; - [n setString:[NSString stringWithFormat:@"# %@", [[textView string] substringWithRange:workingRange]]]; - [n replaceOccurrencesOfRegex:@"\\n(?=.)" withString:@"\n# "]; - [n replaceOccurrencesOfRegex:@"\\n# # " withString:@"\n"]; - [n replaceOccurrencesOfRegex:@"^# # " withString:@""]; + [n setString:[NSString stringWithFormat:@"-- %@", [[textView string] substringWithRange:workingRange]]]; + [n replaceOccurrencesOfRegex:@"\\n(?=.)" withString:@"\n-- "]; + // comment out if at least one line is already commented out + if(!([n isMatchedByRegex:@"(\\n-- --|^-- --)"] && [n isMatchedByRegex:@"(\\n-- |^-- )(?!-)"])) { + [n replaceOccurrencesOfRegex:@"\\n-- -- " withString:@"\n"]; + [n replaceOccurrencesOfRegex:@"^-- -- " withString:@""]; + } [textView setSelectedRange:workingRange]; [textView insertText:n]; |