Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61671ff

Browse files
author
Ignacio Romero Zurbuchen
committed
Fixes crash when double tapping the space bar while the textView was empty. For real this time.
1 parent 0692191 commit 61671ff

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Source/SLKTextViewController.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,12 +1901,18 @@ - (BOOL)textView:(SLKTextView *)textView shouldChangeTextInRange:(NSRange)range
19011901
}
19021902

19031903
// Detects double spacebar tapping, to replace the default "." insert with a formatting symbol, if needed.
1904-
if (textView.isFormattingEnabled && range.location > 0 && text.length > 0 && textView.text.length > 1 &&
1904+
if (textView.isFormattingEnabled && range.location > 0 && text.length > 0 &&
19051905
[[NSCharacterSet whitespaceCharacterSet] characterIsMember:[text characterAtIndex:0]] &&
19061906
[[NSCharacterSet whitespaceCharacterSet] characterIsMember:[textView.text characterAtIndex:range.location - 1]]) {
19071907

19081908
BOOL shouldChange = YES;
19091909

1910+
// Since we are moving 2 characters to the left, we need for to make sure that the string's lenght,
1911+
// before the caret position, is higher than 2.
1912+
if ([textView.text substringToIndex:textView.selectedRange.location].length < 2) {
1913+
return YES;
1914+
}
1915+
19101916
NSRange wordRange = range;
19111917
wordRange.location -= 2; // minus the white space added with the double space bar tapping
19121918

0 commit comments

Comments
 (0)