Skip to content

Commit

Permalink
Fix crash with mismatched begin and end editing calls. (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmshelley authored Aug 4, 2017
1 parent fdc0a67 commit 11258d7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion RichTextVC-iOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "RichTextVC-iOS"
s.version = "2.0.2"
s.version = "2.0.3"
s.summary = "A Rich Text ViewController for iOS."

# This description is used to generate tags and improve search results.
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/RichTextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ open class RichTextViewController: UIViewController {
let previousRange = NSRange(location: range.location - RichTextViewController.bulletedLineStarter.length, length: RichTextViewController.bulletedLineStarter.length)
let bulletedString = "\n" + RichTextViewController.bulletedLineStarter

textView.textStorage.beginEditing()
if let subString = textView.attributedText?.attributedSubstring(from: previousRange).string, subString == RichTextViewController.bulletedLineStarter {
textView.textStorage.beginEditing()
textView.textStorage.replaceCharacters(in: previousRange, with: NSAttributedString(string: "", attributes: textView.typingAttributes))
textView.textStorage.endEditing()
} else {
addText(bulletedString, toTextView: textView, atIndex: range.location)
}
textView.textStorage.endEditing()
textView.selectedRange = NSRange(location: range.location + (bulletedString as NSString).length, length: 0)

return true
Expand Down

0 comments on commit 11258d7

Please sign in to comment.