Skip to content

Commit 864d2bb

Browse files
committed
Handle effective range when no attributes found at location
1 parent 0d21ba9 commit 864d2bb

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Foundation/NSAttributedString.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public class NSAttributedString : NSObject, NSCopying, NSMutableCopying, NSSecur
6464
}
6565

6666
// Update effective range
67-
range.pointee.location = rangePointer.pointee.location
68-
range.pointee.length = rangePointer.pointee.length
67+
let hasAttrs = results.count > 0
68+
range.pointee.location = hasAttrs ? rangePointer.pointee.location : NSNotFound
69+
range.pointee.length = hasAttrs ? rangePointer.pointee.length : 0
6970

7071
return results
7172
}

0 commit comments

Comments
 (0)