         }
         
         if range.length == 0 {
-            if range.location <= textView.text.length - 1 && stringAtRange(NSRange(location: range.location, length: 1)) == spaceAfterNumberCharacter {
+            if range.location <= textView.text.length - 1 && stringAtRange(NSRange(location: range.location, length: 1)) == RichTextViewController.spaceAfterNumberCharacter {
                 if previousSelection.location < range.location {
                     range.location += 1
                 } else {
                     range.location = textView.text.previousIndexOfSubstring("\n", fromIndex: range.location) ?? 0
                 }
-            } else if range.location <= textView.text.length - 2 && stringAtRange(NSRange(location: range.location, length: 2)) == numberedListTrailer {
+            } else if range.location <= textView.text.length - 2 && stringAtRange(NSRange(location: range.location, length: 2)) == RichTextViewController.numberedListTrailer {
                 if previousSelection.location < range.location {
                     range.location += 2
                 } else {
                     range.location = textView.text.previousIndexOfSubstring("\n", fromIndex: range.location) ?? 0
                 }
             } else if range.location > 0 && range.location < textView.text.length - 1 && stringAtRange(NSRange(location: range.location - 1, length: 1)) == "\n",
-                let nextTrailerIndex = textView.text.nextIndexOfSubstring(numberedListTrailer, fromIndex: range.location),
+                let nextTrailerIndex = textView.text.nextIndexOfSubstring(RichTextViewController.numberedListTrailer, fromIndex: range.location),
                 nextLineIndex = textView.text.nextIndexOfSubstring("\n", fromIndex: range.location)
                 where nextTrailerIndex < nextLineIndex {
                     if previousSelection.location < range.location {
-                        range.location = textView.text.nextIndexOfSubstring(numberedListTrailer, fromIndex: range.location) ?? textView.text.length
+                        range.location = textView.text.nextIndexOfSubstring(RichTextViewController.numberedListTrailer, fromIndex: range.location) ?? textView.text.length
                     } else {
                         range.location -= 1
                     }
             }
         } else {
-            if range.location <= textView.text.length - 1 && stringAtRange(NSRange(location: range.location, length: 1)) == spaceAfterNumberCharacter {
+            if range.location <= textView.text.length - 1 && stringAtRange(NSRange(location: range.location, length: 1)) == RichTextViewController.spaceAfterNumberCharacter {
                 if previousSelection.location < range.location {
                     range.location += 1
                     range.length -= 1

                    newLength -= newLength != range.length + 1 ? range.location : 0
                    range.length = newLength
                }
            } else if range.location + range.length <= textView.text.length - 2 && stringAtRange(NSRange(location: range.location + range.length, length: 2)) == numberedListTrailer {
                if previousSelection.length < range.length {
                    range.length += 2
                } else {


public class RichTextViewController: UIViewController {

    static let afterNumberCharacter = "."
    static let spaceAfterNumberCharacter = "\u{00A0}"
    public static let bulletedLineStarter = "\u{2022}\u{00A0}"
    public static var numberedListTrailer: String = {
        return "\(afterNumberCharacter)\(spaceAfterNumberCharacter)"
    }()
    
    var previousSelection = NSRange()

    public var textView = UITextView()
    
    public var regularFont: UIFont?
    public var boldFont: UIFont?
    public var italicFont: UIFont?
    public var boldItalicFont: UIFont?
    
    /// Replaces text in a range with text in parameter
    ///
    /// - parameter range: The range at which to replace the string.
