aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CustomQuery.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r--Source/CustomQuery.m20
1 files changed, 16 insertions, 4 deletions
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];