func setAttributes()

in Sources/TwitterTextEditor/TextEditorView.swift [1559:1575]


    func setAttributes(from attributedString: NSAttributedString) throws {
        guard self.string == attributedString.string else {
            throw SetAttributesError.charactersEdited
        }

        if self == attributedString {
            return
        }

        beginEditing()
        let range = NSRange(location: 0, length: length)
        setAttributes([:], range: range)
        attributedString.enumerateAttributes(in: range, options: []) { (attributes, range, _) in
            addAttributes(attributes, range: range)
        }
        endEditing()
    }