aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CustomQuery.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r--Source/CustomQuery.m30
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 7dc8e4dc..00834f80 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -927,6 +927,36 @@
[textView setSelectedRange:currentQueryRange];
}
+- (void)commentOutQuery
+{
+
+ if(!currentQueryRange.length && ![textView selectedRange].length) {
+ NSBeep();
+ return;
+ }
+
+ NSRange workingRange;
+
+ NSRange oldRange = [textView selectedRange];
+
+ if(oldRange.length)
+ workingRange = oldRange;
+ else
+ 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:@""];
+
+ [textView setSelectedRange:workingRange];
+
+ [textView insertText:n];
+
+ [textView setSelectedRange:NSMakeRange(NSMaxRange(currentQueryRange),0)];
+}
+
#pragma mark -
#pragma mark Accessors