aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-12-29 21:14:17 +0000
committerrowanbeentje <rowan@beent.je>2009-12-29 21:14:17 +0000
commit7753ee58924ee3d8da9177a1c318a28dd0bcd6d9 (patch)
treec9b87947e77adfdb5307884ac5fb90050a7438e2
parentb7bfae119265c7b09dad7160175844198c9289bc (diff)
downloadsequelpro-7753ee58924ee3d8da9177a1c318a28dd0bcd6d9.tar.gz
sequelpro-7753ee58924ee3d8da9177a1c318a28dd0bcd6d9.tar.bz2
sequelpro-7753ee58924ee3d8da9177a1c318a28dd0bcd6d9.zip
- Improve line selection for certain errors ending in numbers, and safety-check selections to prevent crashes. This should address Issue #511.
-rw-r--r--Source/CMTextView.m11
-rw-r--r--Source/CustomQuery.m2
2 files changed, 9 insertions, 4 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index ecc89e71..547a4e0a 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -410,7 +410,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
lineRanges = [[[self string] substringWithRange:[self selectedRange]] lineRangesForRange:NSMakeRange(0, [self selectedRange].length)];
else
lineRanges = [[self string] lineRangesForRange:NSMakeRange(0, [[self string] length])];
- int offset = 0;
+
if(ignLeadingNewLines) // ignore leading empty lines
{
int arrayCount = [lineRanges count];
@@ -418,10 +418,15 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
for (i = 0; i < arrayCount; i++) {
if(NSRangeFromString([lineRanges objectAtIndex:i]).length > 0)
break;
- offset++;
+ lineNumber++;
}
}
- selRange = NSRangeFromString([lineRanges objectAtIndex:lineNumber-1+offset]);
+
+ // Safety-check the line number
+ if (lineNumber > [lineRanges count]) lineNumber = [lineRanges count];
+
+ // Grab the range to select
+ selRange = NSRangeFromString([lineRanges objectAtIndex:lineNumber-1]);
// adjust selRange if a selection was given
if([self selectedRange].length)
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 137ac017..17763ddd 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -631,7 +631,7 @@
// set the error text
[errorText setStringValue:errors];
// select the line x of the first error if error message contains "at line x"
- NSRange errorLineNumberRange = [errors rangeOfRegex:@"([0-9]+)$" options:RKLNoOptions inRange:NSMakeRange(0, [errors length]) capture:1 error:nil];
+ NSRange errorLineNumberRange = [errors rangeOfRegex:@"(?<!key )([0-9]+)$" options:RKLNoOptions inRange:NSMakeRange(0, [errors length]) capture:1 error:nil];
if(errorLineNumberRange.length) // if a line number was found
{
// Get the line number