From 0abbaa9631c3720cdb2612b5c5ae6476ca3ddd99 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sat, 4 Apr 2009 12:40:39 +0000 Subject: =?UTF-8?q?=E2=80=A2=20FIXED=20upper=20case=20of=20e.g.=20'order?= =?UTF-8?q?=5F'=20issue=20-=20in=20addition=20fixed=20issue=20of=20typing?= =?UTF-8?q?=20'order=5F'=20and=20then=20deleteBackward:=20event=20[ticket?= =?UTF-8?q?=20281=20comment=202]=20--=20solved=20by=20looking=20at=20the?= =?UTF-8?q?=20end=20of=20SQL=20keyword=20token=20instead=20at=20begin=20of?= =?UTF-8?q?=20it=20=3D>=20further=20discussion=20"undo=20behaviour"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 91597c9d..07b334a0 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -1093,19 +1093,19 @@ SYNTAX HIGHLIGHTING! switch (token) { case SPT_SINGLE_QUOTED_TEXT: case SPT_DOUBLE_QUOTED_TEXT: - tokenColor = quoteColor; - break; + tokenColor = quoteColor; + break; case SPT_BACKTICK_QUOTED_TEXT: - tokenColor = backtickColor; - break; + tokenColor = backtickColor; + break; case SPT_RESERVED_WORD: - tokenColor = keywordColor; - break; + tokenColor = keywordColor; + break; case SPT_COMMENT: - tokenColor = commentColor; - break; + tokenColor = commentColor; + break; default: - tokenColor = nil; + tokenColor = nil; } if (!tokenColor) continue; @@ -1117,15 +1117,20 @@ SYNTAX HIGHLIGHTING! tokenRange = NSIntersectionRange(tokenRange, textRange); if (!tokenRange.length) continue; - // Is the current token is marked as SQL keyword, uppercase it if required. - if (autouppercaseKeywordsEnabled && - [[self textStorage] attribute:kSQLkeyword atIndex:tokenRange.location effectiveRange:nil]) - { - // Note: Register it for undo doesn't work ?=> unreliable single char undo - // Replace it - [self replaceCharactersInRange:tokenRange withString:[[[self string] substringWithRange:tokenRange] uppercaseString]]; - } - + // If the current token is marked as SQL keyword, uppercase it if required. + unsigned long tokenEnd = tokenRange.location+tokenRange.length-1; // Check the end of the token + if (autouppercaseKeywordsEnabled + && [[self textStorage] attribute:kSQLkeyword atIndex:tokenEnd effectiveRange:nil]) + // check if next char is not a kSQLkeyword; if so then upper case keyword + // @try catch() for catching valid index esp. after deleteBackward: + @try { + if(![[self textStorage] attribute:kSQLkeyword atIndex:tokenEnd+1 effectiveRange:nil]) + // Register it for undo + // [self shouldChangeTextInRange:tokenRange replacementString:[[[self string] substringWithRange:tokenRange] uppercaseString]]; + // NOTE: If one does this registering it ends up in single-character-undo + [self replaceCharactersInRange:tokenRange withString:[[[self string] substringWithRange:tokenRange] uppercaseString]]; + } @catch(id ae) { } + [textStore addAttribute: NSForegroundColorAttributeName value: tokenColor range: tokenRange ]; -- cgit v1.2.3