diff --git a/MacDown/Code/Extension/NSTextView+Autocomplete.m b/MacDown/Code/Extension/NSTextView+Autocomplete.m index a2042b4..4e404aa 100644 --- a/MacDown/Code/Extension/NSTextView+Autocomplete.m +++ b/MacDown/Code/Extension/NSTextView+Autocomplete.m @@ -249,11 +249,15 @@ static NSString * const kMPBlockquoteLinePattern = @"^((?:\\> ?)+).*$"; if (whitespaceCount < 2) return NO; - NSUInteger offset = - ([self.string locationOfFirstNewlineBefore:location] + 1) % 4; + NSUInteger lineStart = [string locationOfFirstNewlineBefore:location] + 1; + if (location <= lineStart) + return NO; + + NSUInteger offset = (location - lineStart) % 4; if (offset == 0) offset = 4; - offset = offset > whitespaceCount ? whitespaceCount : 4; + if (whitespaceCount < offset) + offset = whitespaceCount; NSRange range = NSMakeRange(location - offset, offset); [self replaceCharactersInRange:range withString:@""];