From 0a7642665ea627738ac8a9b858c3ac45c5c0b941 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 27 Aug 2009 20:01:21 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20bug=20while=20uppercasing=20keyword?= =?UTF-8?q?s=20-=20inserting=20a=20char=20within=20an=20already=20marked?= =?UTF-8?q?=20keyword=20doesn't=20end=20up=20in=20inserting=20a=20uppercas?= =?UTF-8?q?e=20char=20if=20resulting=20word=20won't=20be=20a=20new=20keywo?= =?UTF-8?q?rd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 042a76fa..5afc75b4 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -2108,8 +2108,13 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) yyuoffset = textRange.location; yyuleng = 0; yy_switch_to_buffer(yy_scan_string(NSStringUTF8String([selfstr substringWithRange:textRange]))); + // NO if lexer doesn't find a token to suppress auto-uppercasing + // and continue earlier. + BOOL allowToCheckForUpperCase; + // now loop through all the tokens while (token=yylex()){ + allowToCheckForUpperCase = YES; switch (token) { case SPT_SINGLE_QUOTED_TEXT: case SPT_DOUBLE_QUOTED_TEXT: @@ -2131,25 +2136,25 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) tokenColor = variableColor; break; case SPT_WHITESPACE: - tokenColor = nil; + continue; break; default: tokenColor = textColor; + allowToCheckForUpperCase = NO; } - if (!tokenColor) continue; - tokenRange = NSMakeRange(yyuoffset, yyuleng); // make sure that tokenRange is valid (and therefore within textRange) // otherwise a bug in the lex code could cause the the TextView to crash - tokenRange = NSIntersectionRange(tokenRange, textRange); - if (!tokenRange.length) continue; + // NOTE Disabled for testing purposes for speed it up + // tokenRange = NSIntersectionRange(tokenRange, textRange); + // if (!tokenRange.length) continue; // If the current token is marked as SQL keyword, uppercase it if required. tokenEnd = tokenRange.location+tokenRange.length-1; // Check the end of the token - if (autouppercaseKeywords && !delBackwardsWasPressed + if (allowToCheckForUpperCase && autouppercaseKeywords && !delBackwardsWasPressed && [[textStore attribute:kSQLkeyword atIndex:tokenEnd effectiveRange:nil] isEqualToString:kValue]) // check if next char is not a kSQLkeyword or current kSQLkeyword is at the end; // if so then upper case keyword if not already done @@ -2174,6 +2179,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSMutableAttributedStringAddAttributeValueRange(textStore, NSForegroundColorAttributeName, tokenColor, tokenRange); + if(!allowToCheckForUpperCase) continue; + // Add an attribute to be used in the auto-pairing (keyDown:) // to disable auto-pairing if caret is inside of any token found by lex. // For discussion: maybe change it later (only for quotes not keywords?) -- cgit v1.2.3