aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPBundleCommandTextView.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-12-08 12:39:45 +0000
committerBibiko <bibiko@eva.mpg.de>2010-12-08 12:39:45 +0000
commit8b4ae2928e82097e1957ef1873988d8677ac5426 (patch)
tree3b8c984cd2176af981e4d7e95ca402bb2b21167c /Source/SPBundleCommandTextView.m
parentd51530a48813b08d9694fed3a7a24998d495d5b5 (diff)
downloadsequelpro-8b4ae2928e82097e1957ef1873988d8677ac5426.tar.gz
sequelpro-8b4ae2928e82097e1957ef1873988d8677ac5426.tar.bz2
sequelpro-8b4ae2928e82097e1957ef1873988d8677ac5426.zip
• Bundle Editor
- added completion support for shell variables via ESC or F5 or ⌘. - added chance to select something and wrap it into corresponding closing char for ( ' " ` {
Diffstat (limited to 'Source/SPBundleCommandTextView.m')
-rw-r--r--Source/SPBundleCommandTextView.m57
1 files changed, 56 insertions, 1 deletions
diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m
index d5a649bb..2f9066b6 100644
--- a/Source/SPBundleCommandTextView.m
+++ b/Source/SPBundleCommandTextView.m
@@ -337,7 +337,7 @@
[super cut:sender];
}
-- (void) setTabStops
+- (void)setTabStops
{
NSFont *tvFont = [self font];
NSInteger i;
@@ -395,6 +395,54 @@
[paragraphStyle release];
}
+/**
+ * If the textview has a selection, wrap it with the supplied prefix and suffix strings;
+ * return whether or not any wrap was performed.
+ */
+- (BOOL)wrapSelectionWithPrefix:(unichar)prefix
+{
+
+ NSRange currentRange = [self selectedRange];
+
+ // Only proceed if a selection is active
+ if (currentRange.length == 0 || ![self isEditable])
+ return NO;
+
+ unichar matchingCharacter;
+
+ // Set matchingCharacter due to prefix.
+ switch (prefix)
+ {
+ case '(':
+ matchingCharacter = ')';
+ break;
+ case '"':
+ matchingCharacter = '"';
+ break;
+ case '`':
+ matchingCharacter = '`';
+ break;
+ case '\'':
+ matchingCharacter = '\'';
+ break;
+ case '{':
+ matchingCharacter = '}';
+ default:
+ return NO;
+ }
+
+ NSString *selString = [[self string] substringWithRange:currentRange];
+
+ // Replace the current selection with the selected string wrapped in prefix and suffix
+ [self insertText:[NSString stringWithFormat:@"%c%@%c", prefix, selString, matchingCharacter]];
+
+ // Re-select original selection
+ NSRange innerSelectionRange = NSMakeRange(currentRange.location+1, [selString length]);
+ [self setSelectedRange:innerSelectionRange];
+
+ return YES;
+}
+
- (void)keyDown:(NSEvent *)theEvent
{
@@ -410,7 +458,9 @@
return;
}
+ NSString *characters = [theEvent characters];
NSString *charactersIgnMod = [theEvent charactersIgnoringModifiers];
+ unichar insertedCharacter = [characters characterAtIndex:0];
long curFlags = ([theEvent modifierFlags] & allFlags);
if(curFlags & NSCommandKeyMask) {
@@ -452,6 +502,11 @@
[[self delegate] setDoGroupDueToChars];
}
+ // Check to see whether several characters are selected, and if so, wrap them with
+ // the auto-paired characters. This returns false if the selection has zero length.
+ if ([self wrapSelectionWithPrefix:insertedCharacter])
+ return;
+
[super keyDown: theEvent];
}