美文网首页
YYTextView setMarkedText: _repla

YYTextView setMarkedText: _repla

作者: 旧夏2014 | 来源:发表于2019-08-15 14:05 被阅读0次

在YYTextView.m里1471,3347,3351行加越界判断即可:

1471:

if(range.asRange.location+range.asRange.length<=_innerText.length) {

        if(notify) [_inputDelegatetextWillChange:self];

        NSRangenewRange =NSMakeRange(range.asRange.location, text.length);

        [_innerText replaceCharactersInRange:range.asRange withString:text];

        [_innerText yy_removeDiscontinuousAttributesInRange:newRange];

        if(notify) [_inputDelegatetextDidChange:self];

    }

3347:

if (_markedTextRange == nil) {

        _markedTextRange = [YYTextRange rangeWithRange:NSMakeRange(_selectedTextRange.end.offset, markedText.length)];

        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];

        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)];

    }

相关文章

网友评论

      本文标题:YYTextView setMarkedText: _repla

      本文链接:https://www.haomeiwen.com/subject/rxlzjctx.html