Move duplicated code outside of the if

This commit is contained in:
Nate Weaver 2020-04-28 17:31:41 -05:00
parent b7916f7d31
commit fcbfce4ace
1 changed files with 6 additions and 12 deletions

View File

@ -159,6 +159,12 @@ extension NSAttributedString {
tag.append(first)
}
} else if char == ">" && inTag != .none {
let lastRange = attributeRanges.last?.range
let location = lastRange != nil ? lastRange!.location + lastRange!.length : 0
let range = NSRange(location: location, length: result.mutableString.length - location)
attributeRanges.append( (range: range, styles: currentStyles) )
if inTag == .opening {
tagStack.append(tag)
@ -168,12 +174,6 @@ extension NSAttributedString {
result.mutableString.append(delimiter ?? "\"")
}
let lastRange = attributeRanges.last?.range
let location = lastRange != nil ? lastRange!.location + lastRange!.length : 0
let range = NSRange(location: location, length: result.mutableString.length - location)
attributeRanges.append( (range: range, styles: currentStyles) )
if let style = Style(tag: tag) {
currentStyles.insert(style)
}
@ -184,12 +184,6 @@ extension NSAttributedString {
quoteDepth -= 1
}
let lastRange = attributeRanges.last?.range
let location = lastRange != nil ? lastRange!.location + lastRange!.length : 0
let range = NSRange(location: location, length: result.mutableString.length - location)
attributeRanges.append( ( range: range, styles: currentStyles ))
if let style = Style(tag: tag) {
currentStyles.remove(style)
}