diff options
author | rowanbeentje <rowan@beent.je> | 2009-04-30 22:35:03 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-04-30 22:35:03 +0000 |
commit | b086545e95705cb2600a59089c2ade7057597ab9 (patch) | |
tree | e068b871fc5d6dcbae27f1ba0d664beff9850fae /Source | |
parent | c6d9ccf48dcc12c907fd6e86035b5964972ab881 (diff) | |
download | sequelpro-b086545e95705cb2600a59089c2ade7057597ab9.tar.gz sequelpro-b086545e95705cb2600a59089c2ade7057597ab9.tar.bz2 sequelpro-b086545e95705cb2600a59089c2ade7057597ab9.zip |
- Fix indentation behaviour when there are spaces after as well as before the cursor on the current line; now indents to the correct level, instead of increasing indentation incorrectly
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMTextView.m | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 0c35c4c3..25dda47d 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -455,10 +455,12 @@ YY_BUFFER_STATE yy_scan_string (const char *); NSString *currentLine, *indentString = nil; NSScanner *whitespaceScanner; NSRange currentLineRange; + int lineCursorLocation; // Extract the current line based on the text caret or selection start position currentLineRange = [textViewString lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; currentLine = [[NSString alloc] initWithString:[textViewString substringWithRange:currentLineRange]]; + lineCursorLocation = [self selectedRange].location - currentLineRange.location; // Scan all indentation characters on the line into a string whitespaceScanner = [[NSScanner alloc] initWithString:currentLine]; @@ -471,7 +473,13 @@ YY_BUFFER_STATE yy_scan_string (const char *); [self insertNewline:self]; // Replicate the indentation on the previous line if one was found. - if (indentString) [self insertText:indentString]; + if (indentString) { + if (lineCursorLocation < [indentString length]) { + [self insertText:[indentString substringWithRange:NSMakeRange(0, lineCursorLocation)]]; + } else { + [self insertText:indentString]; + } + } // Return to avoid the original implementation, preventing double linebreaks return; |