From 6e83f452684330b881cc2d57c57ea981934ba18a Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 20 Apr 2009 14:01:50 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20selectLineNumber:x=20to=20CMTextVie?= =?UTF-8?q?w=20to=20be=20able=20to=20select=20the=20line=20x=20=E2=80=A2?= =?UTF-8?q?=20added=20error=20highlighting=20of=20the=20first=20mentioned?= =?UTF-8?q?=20error=20-=20if=20a=20"near=20message"=20error=20is=20provide?= =?UTF-8?q?d=20select=20that=20message=20otherwise=20select=20the=20entire?= =?UTF-8?q?=20error=20line=20and=20scrolls=20to=20it=20-=20if=20no=20"at?= =?UTF-8?q?=20line=20x"=20and=20no=20"near=20message"=20is=20given=20do=20?= =?UTF-8?q?nothing=20-=20if=20a=20selection=20was=20given=20and=20the=20us?= =?UTF-8?q?er=20pressed=20"runAll"=20destroy=20the=20selection=20before=20?= =?UTF-8?q?error=20checking;=20if=20no=20error=20was=20found=20reconstruct?= =?UTF-8?q?=20that=20selection=20(to=20be=20able=20to=20distinguish=20betw?= =?UTF-8?q?een=20"runSelection"=20and=20"runAll"=20plus=20selection)=20*?= =?UTF-8?q?=20changed=20slightly=20the=20trigger=20for=20syntax=20highligh?= =?UTF-8?q?ting/auto-uppercasing=20for=20better=20scrollToRange=20behaviou?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'Source/CustomQuery.m') diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 3d8b5383..980116a3 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -54,14 +54,23 @@ queries = [queryParser splitStringByCharacter:';']; [queryParser release]; + NSRange curRange = [textView selectedRange]; + // Unselect a selection if given to avoid interferring with error highlighting + [textView setSelectedRange:NSMakeRange(curRange.location, 0)]; [self performQueries:queries]; + // If no error was selected reconstruct a given selection + if([textView selectedRange].length == 0) + [textView setSelectedRange:curRange]; // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase - [textView setSelectedRange:NSMakeRange(0,0)]; + NSRange oldRange = [textView selectedRange]; + [textView setSelectedRange:NSMakeRange(oldRange.location,0)]; [textView insertText:@""]; + [textView setSelectedRange:oldRange]; + // Select the text of the query textView for re-editing - [textView selectAll:self]; + //[textView selectAll:self]; } /* @@ -93,7 +102,7 @@ // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase // and preserve the selection - [textView setSelectedRange:NSMakeRange(0,0)]; + [textView setSelectedRange:NSMakeRange(selectedRange.location,0)]; [textView insertText:@""]; [textView setSelectedRange:selectedRange]; @@ -430,8 +439,36 @@ sets the tableView columns corresponding to the mysql-result } [prefs setObject:menuItems forKey:@"queryHistory"]; + // Error checking if ( [errors length] ) { + // set the error text [errorText setStringValue:errors]; + // select the line x of the first error if error message contains "at line x" + NSError *err1 = NULL; + NSRange errorLineNumberRange = [errors rangeOfRegex:@"at line ([0-9]+)" options:RKLNoOptions inRange:NSMakeRange(0, [errors length]) capture:1 error:&err1]; + if(errorLineNumberRange.length) // if a line number was found + { + // Get the line number + unsigned int errorAtLine = [[errors substringWithRange:errorLineNumberRange] intValue]; + [textView selectLineNumber:errorAtLine ignoreLeadingNewLines:YES]; + + // Check for near message + NSRange errorNearMessageRange = [errors rangeOfRegex:@"use near '(.*?)'" options:(RKLMultiline|RKLDotAll) inRange:NSMakeRange(0, [errors length]) capture:1 error:&err1]; + if(errorNearMessageRange.length) // if a "near message" was found + { + // Get the line of the first error via the current selected line + NSRange lineRange = [[textView string] lineRangeForRange:NSMakeRange([textView selectedRange].location, 0)]; + // Build the range to search for nearMessage (beginning from the error line to try to avoid mismatching) + NSRange theRange = NSMakeRange(lineRange.location, [[textView string] length]-lineRange.location); + // 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 + textNearMessageRange = NSMakeRange(textNearMessageRange.location+lineRange.location, textNearMessageRange.length); + // Select the near message and scroll to it + [textView setSelectedRange:textNearMessageRange]; + [textView scrollRangeToVisible:textNearMessageRange]; + } + } } else { [errorText setStringValue:NSLocalizedString(@"There were no errors.", @"text shown when query was successfull")]; } -- cgit v1.2.3