diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-05-19 09:29:00 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-05-19 09:29:00 +0000 |
commit | 15796e40fba251a00197c66f2ecf04cbf086a034 (patch) | |
tree | da53a1f57325bdd25024aeef913aa4b62b4e55b9 /Source/CMTextView.m | |
parent | 8e6012bb097bbc5b3456bc9b6a4f6b90cb4e6c15 (diff) | |
download | sequelpro-15796e40fba251a00197c66f2ecf04cbf086a034.tar.gz sequelpro-15796e40fba251a00197c66f2ecf04cbf086a034.tar.bz2 sequelpro-15796e40fba251a00197c66f2ecf04cbf086a034.zip |
• skip auto-pairing if the caret is adjoined to an alphanumeric character except if the inserted character will be a “(” and the caret is located at the end of a string then process the auto-pairing
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r-- | Source/CMTextView.m | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 6f379f90..8803af2e 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -124,6 +124,32 @@ YY_BUFFER_STATE yy_scan_string (const char *); } /* + * Checks if the caret adjoins to an alphanumeric char |word or word| or wo|rd + * Exception for word| and char is a “(” to allow e.g. auto-pairing () for functions + */ +- (BOOL) isCaretAdjacentToAlphanumCharWithInsertionOf:(unichar)aChar +{ + unsigned int caretPosition = [self selectedRange].location; + NSCharacterSet *alphanum = [NSCharacterSet alphanumericCharacterSet]; + BOOL leftIsAlphanum = NO; + BOOL rightIsAlphanum = NO; + BOOL charIsOpenBracket = (aChar == '('); + + // Check previous/next character for being alphanum + // @try block for bounds checking + @try + { + leftIsAlphanum = [alphanum characterIsMember:[[self string] characterAtIndex:caretPosition-1]] && !charIsOpenBracket; + } @catch(id ae) { } + @try { + rightIsAlphanum= [alphanum characterIsMember:[[self string] characterAtIndex:caretPosition]]; + + } @catch(id ae) { } + + return (leftIsAlphanum ^ rightIsAlphanum || leftIsAlphanum && rightIsAlphanum); +} + +/* * Checks if the caret is wrapped by auto-paired characters. * e.g. [| := caret]: "|" */ @@ -328,11 +354,13 @@ YY_BUFFER_STATE yy_scan_string (const char *); return; } - // If the caret is inside a text string, without any selection, skip autopairing. + // If the caret is inside a text string, without any selection, and not adjoined to an alphanumeric char + // (exception for '(' ) 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 // over; e.g. [| := caret]: "foo|" and press " => only caret will be moved "foo"| - if(![self isNextCharMarkedBy:kAPlinked withValue:kAPval] && [self isNextCharMarkedBy:kLEXToken withValue:kLEXTokenValue] && ![self selectedRange].length) { + if( ([self isCaretAdjacentToAlphanumCharWithInsertionOf:insertedCharacter] && ![self isNextCharMarkedBy:kAPlinked withValue:kAPval] && ![self selectedRange].length) + || (![self isNextCharMarkedBy:kAPlinked withValue:kAPval] && [self isNextCharMarkedBy:kLEXToken withValue:kLEXTokenValue] && ![self selectedRange].length)) { [super keyDown:theEvent]; return; } |