aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-04-21 12:58:34 +0000
committerBibiko <bibiko@eva.mpg.de>2009-04-21 12:58:34 +0000
commitaa60169e5a05bc91f2cf4f4f2377ca894755ef9e (patch)
tree578b0c45d242a52f54f49dff511525b2bc6275b4
parent1f71bfce7c1b1e50efcdf82a63b80f661909af48 (diff)
downloadsequelpro-aa60169e5a05bc91f2cf4f4f2377ca894755ef9e.tar.gz
sequelpro-aa60169e5a05bc91f2cf4f4f2377ca894755ef9e.tar.bz2
sequelpro-aa60169e5a05bc91f2cf4f4f2377ca894755ef9e.zip
• slightly improved "Run Previous" detection
- now it recognizes if the line is empty after the caret position; if not "Run Current" is set
-rw-r--r--Source/CustomQuery.m30
1 files changed, 26 insertions, 4 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index bf3390bc..63f6986b 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -590,9 +590,25 @@ sets the tableView columns corresponding to the mysql-result
queryPosition += [[queries objectAtIndex:i] length];
if (queryPosition >= position) {
- // If lookbehind is enabled, determine whether it's valid
- if (doLookBehind) {
- if (i && [[[[textView string] substringWithRange:NSMakeRange(queryStartPosition, position - queryStartPosition)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0) {
+ // If lookbehind is enabled, determine whether it's valid and check
+ // if after the caret position are only white spaces or newlines
+ if (*doLookBehind) {
+ NSCharacterSet *trimSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
+ NSString *string = [textView string];
+ unsigned int curCaretPosition = [textView selectedRange].location;
+ NSRange curlineRange = [string lineRangeForRange:NSMakeRange(curCaretPosition, 0)];
+ NSString *lineTailFromCaret = [[string substringWithRange:
+ NSMakeRange([textView selectedRange].location,
+ curlineRange.length + curlineRange.location - curCaretPosition)] stringByTrimmingCharactersInSet:trimSet];
+
+ if (i
+ &&
+ ![[[string substringWithRange:
+ NSMakeRange(queryStartPosition, position - queryStartPosition)] stringByTrimmingCharactersInSet:trimSet] length]
+ &&
+ ![lineTailFromCaret length]
+ )
+ {
query = [NSString stringWithString:[queries objectAtIndex:i-1]];
break;
}
@@ -1068,7 +1084,13 @@ traps enter key and
if (!updateQueryButtons && [[textView string] rangeOfString:@";" options:0 range:NSMakeRange(movedRangeStart, movedRangeLength)].location != NSNotFound) updateQueryButtons = TRUE;
if (!updateQueryButtons && ![runSelectionButton isEnabled] && selectionPosition > oldSelection.location
&& [[[[textView string] substringWithRange:NSMakeRange(movedRangeStart, movedRangeLength)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]) updateQueryButtons = TRUE;
- if (!updateQueryButtons && [[runSelectionButton title] isEqualToString:NSLocalizedString(@"Run Current", @"Title of button to run current query in custom query view")]) {
+ if (!updateQueryButtons &&
+ (
+ [[runSelectionButton title] isEqualToString:NSLocalizedString(@"Run Current", @"Title of button to run current query in custom query view")]
+ ||
+ [[runSelectionButton title] isEqualToString:NSLocalizedString(@"Run Previous", @"Title of button to run query just before text caret in custom query view")]
+ )
+ ) {
int charPosition;
unichar theChar;
for (charPosition = selectionPosition; charPosition > 0; charPosition--) {