Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions Aztec/Classes/TextKit/HTMLStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,13 @@ open class HTMLStorage: NSTextStorage {
endEditing()
}

override open func addAttribute(_ name: String, value: Any, range: NSRange) {
textStore.addAttribute(name, value: value, range: range)
}

override open func removeAttribute(_ name: String, range: NSRange) {
textStore.removeAttribute(name, range: range)
}

override open func replaceCharacters(in range: NSRange, with str: String) {
beginEditing()

textStore.replaceCharacters(in: range, with: str)
edited([.editedAttributes, .editedCharacters], range: range, changeInLength: string.characters.count - range.length)

colorizeHTML()
endEditing()
}

Expand All @@ -106,12 +99,8 @@ open class HTMLStorage: NSTextStorage {
textStore.replaceCharacters(in: range, with: attrString)
edited([.editedAttributes, .editedCharacters], range: range, changeInLength: attrString.length - range.length)

endEditing()
}

override open func processEditing() {
colorizeHTML()
super.processEditing()
endEditing()
}
}

Expand All @@ -129,6 +118,7 @@ private extension HTMLStorage {
addAttribute(NSFontAttributeName, value: font, range: fullStringRange)

let tags = RegExes.html.matches(in: string, options: [], range: fullStringRange)

for tag in tags {
addAttribute(NSForegroundColorAttributeName, value: tagColor, range: tag.range)

Expand All @@ -142,6 +132,8 @@ private extension HTMLStorage {
for comment in comments {
addAttribute(NSForegroundColorAttributeName, value: commentColor, range: comment.range)
}

edited(.editedAttributes, range: fullStringRange, changeInLength: 0)
}
}

Expand Down