From b086545e95705cb2600a59089c2ade7057597ab9 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 30 Apr 2009 22:35:03 +0000 Subject: - 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 --- Source/CMTextView.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3