Skip to content

Commit

Permalink
Make how we handle typingAttributes safer
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Mar 24, 2022
1 parent 368f1f7 commit cc577a1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Zavala/Editor/Row/EditorRowTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ extension EditorRowTextView: NSTextStorageDelegate {
func textStorage(_ textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorage.EditActions, range editedRange: NSRange, changeInLength delta: Int) {

// If you access the typingAttributes while the attributedString is zero, you will crash randomly
guard attributedText.length > 0 else { return }

var newTypingAttributes = typingAttributes
newTypingAttributes.removeValue(forKey: .font)
var newTypingAttributes: [NSAttributedString.Key : Any]
if attributedText.length > 0 {
newTypingAttributes = typingAttributes
newTypingAttributes.removeValue(forKey: .font)
} else {
newTypingAttributes = [NSAttributedString.Key : Any]()
}

textStorage.enumerateAttributes(in: editedRange, options: .longestEffectiveRangeNotRequired) { (attributes, range, _) in
var newAttributes = attributes
Expand Down

0 comments on commit cc577a1

Please sign in to comment.