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

View File

@ -159,6 +159,12 @@ extension NSAttributedString {
tag.append(first) tag.append(first)
} }
} else if char == ">" && inTag != .none { } 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 { if inTag == .opening {
tagStack.append(tag) tagStack.append(tag)
@ -168,12 +174,6 @@ extension NSAttributedString {
result.mutableString.append(delimiter ?? "\"") 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) { if let style = Style(tag: tag) {
currentStyles.insert(style) currentStyles.insert(style)
} }
@ -184,12 +184,6 @@ extension NSAttributedString {
quoteDepth -= 1 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) { if let style = Style(tag: tag) {
currentStyles.remove(style) currentStyles.remove(style)
} }