From 8291dd4ec6d62f2866b3d2cb047837a8ef0c7397 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sun, 26 Jul 2015 22:41:11 +0800 Subject: [PATCH] Insert blockquote prefix for blank lines too Similar logic to blank-line indentation. See 61e4a73 and 4d98888. Fix #383. Side effect: This patch also make list item insertion work with empty lines - a backward-incompatible behaviAoural change. But this seems to be what people want, so let's roll with it for now. We can always change this later if reports appear. --- MacDown/Code/Extension/NSTextView+Autocomplete.m | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/MacDown/Code/Extension/NSTextView+Autocomplete.m b/MacDown/Code/Extension/NSTextView+Autocomplete.m index 1995664..db785ad 100644 --- a/MacDown/Code/Extension/NSTextView+Autocomplete.m +++ b/MacDown/Code/Extension/NSTextView+Autocomplete.m @@ -339,15 +339,18 @@ static NSString * const kMPBlockquoteLinePattern = @"^((?:\\> ?)+).*$"; [lines enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { NSString *line = obj; if (line.length) - { totalShift += prefixLength; - if (!isMarked) - line = [prefix stringByAppendingString:line]; - else - line = [line substringFromIndex:prefixLength]; - } + if (!isMarked) + line = [prefix stringByAppendingString:line]; + else + line = [line substringFromIndex:prefixLength]; [modLines addObject:line]; }]; + if ([modLines.lastObject isEqualToString:prefix]) + { + [modLines removeLastObject]; + [modLines addObject:@""]; + } NSString *processed = [modLines componentsJoinedByString:@"\n"]; [self insertText:processed replacementRange:lineRange];