From 6e4d0662303ecd6b3f953ff3313965835a9b8074 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 2 Apr 2009 22:47:54 +0000 Subject: =?UTF-8?q?=20-=20Improves=20autopairing=20to=20no=20longer=20auto?= =?UTF-8?q?pair=20different=20quote=20characters=20within=20a=20quoted=20s?= =?UTF-8?q?tring,=20and=20also=20to=20no=20longer=20autoquote=20escaped=20?= =?UTF-8?q?characters=20within=20a=20quoted=20string.=20=20Also=20adds=20s?= =?UTF-8?q?yntax=20highlighting=20to=20`-enclosed=20strings.=20=20Further?= =?UTF-8?q?=20thanks=20to=20Hans-J=C3=B6rg=20Bibiko=20for=20these=20furthe?= =?UTF-8?q?r=20improvements=20to=20his=20original=20patch=20(see=20http://?= =?UTF-8?q?code.google.com/p/sequel-pro/issues/detail=3Fid=3D208=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/CMTextView.m b/Source/CMTextView.m index cfd42884..67d2b39b 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -138,6 +138,35 @@ YY_BUFFER_STATE yy_scan_string (const char *); return; } + // When a quote character is being inserted into a string quoted with other + // quote characters, or if it's the same character but is escaped, don't + // automatically match it. + if( + // Only for " ` or ' quote characters + (insertedCharacter == '\'' || insertedCharacter == '"' || insertedCharacter == '`') + + // And if the next char marked as linked auto-pair + && [self isNextCharMarkedBy:kAPlinked] + + // And we are inside a quoted string + && [self isNextCharMarkedBy:kWQquoted] + + // And there is no selection, just the text caret + && ![self selectedRange].length + + && ( + // And the user is inserting an escaped string + [[self string] characterAtIndex:[self selectedRange].location-1] == '\\' + + // Or the user is inserting a character not matching the characters used to quote this string + || [[self string] characterAtIndex:[self selectedRange].location] != insertedCharacter + ) + ) + { + [super keyDown: theEvent]; + return; + } + // If the caret is inside a text string, without any selection, skip autopairing. // There is one exception to this - if the caret is before a linked pair character, // processing continues in order to check whether the next character should be jumped @@ -819,7 +848,8 @@ sets self as delegate for the textView's textStorage to enable syntax highlighti NSColor *commentColor = [NSColor colorWithDeviceRed:0.000 green:0.455 blue:0.000 alpha:1.000]; NSColor *quoteColor = [NSColor colorWithDeviceRed:0.769 green:0.102 blue:0.086 alpha:1.000]; NSColor *keywordColor = [NSColor colorWithDeviceRed:0.200 green:0.250 blue:1.000 alpha:1.000]; - + NSColor *backtickColor = [NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.658 alpha:1.000]; + NSColor *tokenColor; int token; @@ -845,6 +875,9 @@ sets self as delegate for the textView's textStorage to enable syntax highlighti case SPT_DOUBLE_QUOTED_TEXT: tokenColor = quoteColor; break; + case SPT_BACKTICK_QUOTED_TEXT: + tokenColor = backtickColor; + break; case SPT_RESERVED_WORD: tokenColor = keywordColor; break; -- cgit v1.2.3