Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update YYTextView.m #895

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions YYText/YYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1466,11 +1466,13 @@ - (void)_replaceRange:(YYTextRange *)range withText:(NSString *)text notifyToDel
if (notify) [_inputDelegate selectionDidChange:self];
}
}
if (notify) [_inputDelegate textWillChange:self];
NSRange newRange = NSMakeRange(range.asRange.location, text.length);
[_innerText replaceCharactersInRange:range.asRange withString:text];
[_innerText yy_removeDiscontinuousAttributesInRange:newRange];
if (notify) [_inputDelegate textDidChange:self];
if (range.asRange.location+range.asRange.length <= _innerText.length) {
if (notify) [_inputDelegate textWillChange:self];
NSRange newRange = NSMakeRange(range.asRange.location, text.length);
[_innerText replaceCharactersInRange:range.asRange withString:text];
[_innerText yy_removeDiscontinuousAttributesInRange:newRange];
if (notify) [_inputDelegate textDidChange:self];
}
}

/// Save current typing attributes to the attributes holder.
Expand Down Expand Up @@ -3344,11 +3346,15 @@ - (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRang
if (!markedText) markedText = @"";
if (_markedTextRange == nil) {
_markedTextRange = [YYTextRange rangeWithRange:NSMakeRange(_selectedTextRange.end.offset, markedText.length)];
[_innerText replaceCharactersInRange:NSMakeRange(_selectedTextRange.end.offset, 0) withString:markedText];
if (_selectedTextRange.end.offset<=_innerText.length) {
[_innerText replaceCharactersInRange:NSMakeRange(_selectedTextRange.end.offset, 0) withString:markedText];
}
_selectedTextRange = [YYTextRange rangeWithRange:NSMakeRange(_selectedTextRange.start.offset + selectedRange.location, selectedRange.length)];
} else {
_markedTextRange = [self _correctedTextRange:_markedTextRange];
[_innerText replaceCharactersInRange:_markedTextRange.asRange withString:markedText];
if (_markedTextRange.asRange.location+_markedTextRange.asRange.length<=_innerText.length) {
[_innerText replaceCharactersInRange:_markedTextRange.asRange withString:markedText];
}
_markedTextRange = [YYTextRange rangeWithRange:NSMakeRange(_markedTextRange.start.offset, markedText.length)];
_selectedTextRange = [YYTextRange rangeWithRange:NSMakeRange(_markedTextRange.start.offset + selectedRange.location, selectedRange.length)];
}
Expand Down