Fix whitespaces calculation logic for deletion

Fix #176
This commit is contained in:
Tzu-ping Chung
2014-10-03 10:44:33 +08:00
parent 2731ecc42e
commit cdd1be0f8a
@@ -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:@""];