     ///
     public func setHTMLUndoable(_ html: String) {
         replace(storage.rangeOfEntireString, withHTML: html)
-        recalculateTypingAttributes(at: selectedRange.location)
+        recalculateTypingAttributes()
     }
 
     /// Loads the specified HTML into the editor.

        }
    }
    
    /// Only call this method when sure that the typingAttributes need to be recalculated.  Keep in mind that
    /// recalculating the typingAttributes in the wrong moment can cause trouble (for example reverting a decision
    /// by the user to turn a style off).
    ///
    private func recalculateTypingAttributes(at location: Int) {
        

        
        set {
            if let start = newValue?.start {
                // We need to calculate the new typing attributes before we change the selected text range.
                // This is because as soon as we change the selected text range bellow, a call to
                // `textViewDidChangeSelection(_:)` will be triggered and we want the typing attributes to
                // be updated by then.
                let position = self.offset(from: self.beginningOfDocument, to: start)
                recalculateTypingAttributes(at: position)
            }
