Skip to content

Commit

Permalink
Merge pull request #35 from CodingFriends/fix/28-crash-untab-eof
Browse files Browse the repository at this point in the history
Fix crash when untabbing at end of file #28
  • Loading branch information
greimers authored Feb 23, 2020
2 parents 82a4de0 + 8cf1c23 commit fb55861
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/Tincta/TextEditor/TCTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ - (void)insertBacktab:(id)sender {
NSInteger selLength = selRange.length;
NSInteger selMax = NSMaxRange(selRange);
NSString* text = [self string];


NSRange lineRange = [text lineRangeForRange:NSMakeRange(selLoc, 0)];
NSInteger lineStart = lineRange.location;
while (lineStart <= selMax) { //iterate over all selected lines
Expand Down Expand Up @@ -317,13 +319,13 @@ - (void)insertBacktab:(id)sender {
if (selLoc > self.string.length || selLoc < 0) {
selLoc = 0;
}
} else if ((lineStart >= selLoc)&& [text characterAtIndex:lineStart] == '\t') {
} else if ((lineStart >= selLoc) && (text.length > lineStart) && [text characterAtIndex:lineStart] == '\t') {
//remove tab at line start
stringToReplace = @"\t";
blankLength = 1;
tabReplaceRange = NSMakeRange(lineStart, blankLength);
selLength -= blankLength;
} else if ((lineStart >= selLoc)&& [text characterAtIndex:lineStart] == ' ') {
} else if ((lineStart >= selLoc) && (text.length > lineStart) &&[text characterAtIndex:lineStart] == ' ') {
//remove blanks at line start
blankLength = 0;
NSInteger tabLength = tabBlankLength;
Expand Down

0 comments on commit fb55861

Please sign in to comment.