From 86c675a07f191ebb499f5cb623401654e1e6d3d9 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 24 Apr 2024 16:41:38 -0500 Subject: [PATCH] fixed color attribute Signed-off-by: Matt Bruce --- VDS/Components/Label/Attributes/ColorLabelAttribute.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift index 50229ab0..0e6dd653 100644 --- a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift @@ -31,12 +31,14 @@ public struct ColorLabelAttribute: LabelAttributeModel { } public func setAttribute(on attributedString: NSMutableAttributedString) { - guard isValidRange(on: attributedString) else { return } - var colorRange = range if length == 0 && location == 0 { colorRange = .init(location: location, length: attributedString.length) + if !attributedString.isValid(range: colorRange) { return } + } else { + guard isValidRange(on: attributedString) else { return } } + let attributeKey = isForegroundColor ? NSAttributedString.Key.foregroundColor : NSAttributedString.Key.backgroundColor attributedString.removeAttribute(attributeKey, range: colorRange) attributedString.addAttribute(attributeKey, value: color, range: colorRange)