Delete tab more naturally

This commit is contained in:
1024jp 2016-06-09 20:46:16 +09:00
parent 6674e8540f
commit a040ad3320
2 changed files with 12 additions and 13 deletions

View File

@ -26,6 +26,7 @@ develop
- Remove “Set as Default” button in the editor opacity panel.
- Change specification not to treat full-width spaces as indent.
- Open sidebar inward on Yosemite.
- Make indent deletion more naturally.
- Remove byte count display in document inspector.
- Display dialogs while changing file encoding as a document-modal sheet.
- Display also an accurate file size in document inspector.

View File

@ -539,20 +539,18 @@ static NSCharacterSet *kMatchingClosingBracketsSet;
// delete tab
if ((selectedRange.length == 0) && [self isAutoTabExpandEnabled]) {
NSUInteger tabWidth = [self tabWidth];
NSInteger column = [[self string] columnOfLocation:selectedRange.location tabWidth:tabWidth];
NSInteger targetWidth = tabWidth - (column % tabWidth);
NSRange indentRange = [[self string] rangeOfIndentAtIndex:selectedRange.location];
if (selectedRange.location >= targetWidth) {
NSRange targetRange = NSMakeRange(selectedRange.location - targetWidth, targetWidth);
BOOL shouldDelete = NO;
for(NSUInteger i = targetRange.location; i < NSMaxRange(targetRange); i++ ) {
shouldDelete = ([[self string] characterAtIndex:i] == ' ');
if (!shouldDelete) { break; }
}
if (shouldDelete) {
[self setSelectedRange:targetRange];
if (selectedRange.location <= NSMaxRange(indentRange)) {
NSUInteger tabWidth = [self tabWidth];
NSInteger column = [[self string] columnOfLocation:selectedRange.location tabWidth:tabWidth];
NSInteger targetLength = tabWidth - (column % tabWidth);
if (selectedRange.location >= targetLength) {
NSRange targetRange = NSMakeRange(selectedRange.location - targetLength, targetLength);
if ([[[self string] substringWithRange:targetRange] isEqualToString:[NSString stringWithSpaces:targetLength]]) {
[self setSelectedRange:targetRange];
}
}
}
}