From 7591371032bbb7956b71ee5d70c0c3139872e3dd Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 29 Jan 2010 14:22:46 +0000 Subject: =?UTF-8?q?=E2=80=A2=20further=20tiny=20improvements=20to=20avoid?= =?UTF-8?q?=20exceptional=20cases=20while=20highlighting=20the=20erroneous?= =?UTF-8?q?=20query=20-=20added=20check=20for=20near=20message=20length=20?= =?UTF-8?q?-=20make=20an=20intersection=20with=20the=20buffer=20range=20be?= =?UTF-8?q?fore=20selecting=20=E2=80=A2=20text=20macro=20-=20each=20select?= =?UTF-8?q?ion=20of=20a=20snippet=20breaks=20the=20undo=20buffer=20-=20not?= =?UTF-8?q?e:=20undo=20behaviour=20while=20text=20macro=20session=20is=20a?= =?UTF-8?q?ctive=20needs=20to=20be=20solved=20=E2=87=A2=20work=20in=20prog?= =?UTF-8?q?ress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'Source/CustomQuery.m') 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]; } -- cgit v1.2.3