@@ -131,30 +131,19 @@ - (void)removeTypingAttributes {
131131}
132132
133133- (BOOL )handleBackspaceInRange : (NSRange )range replacementText : (NSString *)text {
134- if (
135- [self detectStyle: _input->textView.selectedRange] &&
136- NSEqualRanges (_input->textView.selectedRange, NSMakeRange (0 , 0 )) &&
137- [text isEqualToString:@""]
138- ) {
139- // removing first list point by backspacing doesn't remove typing attributes because it doesn't run textViewDidChange
140- // so we try guessing that a point should be deleted here
134+ if ([self detectStyle: _input->textView.selectedRange] && text.length == 0 ) {
135+ // backspace while the style is active
136+
141137 NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange: _input->textView.selectedRange];
142- [self removeAttributes: paragraphRange];
143- return YES ;
144- } else if (
145- [self detectStyle: _input->textView.selectedRange] &&
146- [text isEqualToString: @" " ]
147- ) {
148- // other case; make sure removing all the (non newline) text from a list item also removes the item itself
149- NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange: range];
150- NSValue *nonNewlineVal = [ParagraphsUtils getNonNewlineRangesIn: _input->textView range: paragraphRange].firstObject ;
151- if (nonNewlineVal == nullptr ) {
152- return NO ;
153- }
154- NSRange nonNewlineRange = [nonNewlineVal rangeValue ];
155- if (NSEqualRanges (range, nonNewlineRange)) {
156- [TextInsertionUtils replaceText: text at: range additionalAttributes: nullptr input: _input withSelection: YES ];
157- [self removeAttributes: NSMakeRange (range.location, 0 )];
138+
139+ if (NSEqualRanges (_input->textView .selectedRange , NSMakeRange (0 , 0 ))) {
140+ // a backspace on the very first input's line list point
141+ // it doesn't run textVieDidChange so we need to manually remove attributes
142+ [self removeAttributes: paragraphRange];
143+ return YES ;
144+ } else if (range.location == paragraphRange.location - 1 ) {
145+ // same case in other lines; here, the removed range location will be exactly 1 less than paragraph range location
146+ [self removeAttributes: paragraphRange];
158147 return YES ;
159148 }
160149 }
0 commit comments