diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-01-29 14:22:46 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-01-29 14:22:46 +0000 |
commit | 7591371032bbb7956b71ee5d70c0c3139872e3dd (patch) | |
tree | 9367852ee7b90852eb23f753bc474c6c9e2763e9 /Source/CustomQuery.m | |
parent | a0f3e12600411888242efd76959a124de74ee630 (diff) | |
download | sequelpro-7591371032bbb7956b71ee5d70c0c3139872e3dd.tar.gz sequelpro-7591371032bbb7956b71ee5d70c0c3139872e3dd.tar.bz2 sequelpro-7591371032bbb7956b71ee5d70c0c3139872e3dd.zip |
• further tiny improvements to avoid exceptional cases while highlighting the erroneous query
- added check for near message length
- make an intersection with the buffer range before selecting
• text macro - each selection of a snippet breaks the undo buffer
- note: undo behaviour while text macro session is active needs to be solved ⇢ work in progress
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r-- | Source/CustomQuery.m | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 2ce831f4..9600d929 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -701,21 +701,33 @@ { // Get the line number NSUInteger errorAtLine = [[errors substringWithRange:errorLineNumberRange] integerValue]; - NSUInteger lineOffset = [textView getLineNumberForCharacterIndex:queryTextViewStartPosition] - 1; + NSUInteger lineOffset = [textView getLineNumberForCharacterIndex:[self queryTextRangeForQuery:firstErrorOccuredInQuery startPosition:queryStartPosition].location] - 1; [textView selectLineNumber:errorAtLine+lineOffset ignoreLeadingNewLines:YES]; // Check for near message NSRange errorNearMessageRange = [errors rangeOfRegex:@"[( ]'(.+)'[ -]" options:(RKLMultiline|RKLDotAll) inRange:NSMakeRange(0, [errors length]) capture:1L error:nil]; - if(errorNearMessageRange.length) // if a "near message" was found + if(errorNearMessageRange.length > 2) // if a "near message" was found { + NSUInteger bufferLength = [[textView string] length]; + + NSRange bufferRange = NSMakeRange(0, bufferLength); + // Build the range to search for nearMessage (beginning from queryStartPosition to try to avoid mismatching) - NSRange theRange = NSMakeRange(queryStartPosition, [[textView string] length]-queryStartPosition); + NSRange theRange = NSMakeRange(queryStartPosition, bufferLength-queryStartPosition); + theRange = NSIntersectionRange(bufferRange, theRange); + // Get the range in textView of the near message NSRange textNearMessageRange = [[[textView string] substringWithRange:theRange] rangeOfString:[errors substringWithRange:errorNearMessageRange] options:NSLiteralSearch]; + // Correct the near message range relative to queryStartPosition textNearMessageRange = NSMakeRange(textNearMessageRange.location+queryStartPosition, textNearMessageRange.length); + textNearMessageRange = NSIntersectionRange(bufferRange, textNearMessageRange); + // Select the near message and scroll to it - [textView setSelectedRange:textNearMessageRange]; + if(textNearMessageRange.length > 0) { + [textView setSelectedRange:textNearMessageRange]; + [textView scrollRangeToVisible:textNearMessageRange]; + } } } else { // Select first erroneous query entirely @@ -729,6 +741,7 @@ } else { // select the query for which the first error was detected queryRange = [self queryTextRangeForQuery:firstErrorOccuredInQuery startPosition:queryStartPosition]; + queryRange = NSIntersectionRange(NSMakeRange(0, [[textView string] length]), queryRange); [textView setSelectedRange:queryRange]; [textView scrollRangeToVisible:queryRange]; } |