     }
 
 
+    private func updateTypingAttributes() {
+        if (textStorage.length > 0){
+            let location = max(0,min(selectedRange.location, textStorage.length-1))
+            typingAttributes = textStorage.attributes(at: location, effectiveRange: nil)
+        }
+    }
     /// Adds or removes a ordered list style from the specified range.
     ///
     /// - Parameter range: The NSRange to edit.

        let formatter = TextListFormatter(style: .ordered, placeholderAttributes: typingAttributes)
        let newSelectedRange = formatter.toggle(in: textStorage, at: range)
        selectedRange = newSelectedRange ?? selectedRange
        typingAttributes = textStorage.attributes(at: selectedRange.location, effectiveRange: nil)
    }



        let formatter = TextListFormatter(style: .unordered, placeholderAttributes: typingAttributes)
        let newSelectedRange = formatter.toggle(in: textStorage, at: range)
        selectedRange = newSelectedRange ?? selectedRange
        updateTypingAttributes()
    }


