Created
February 15, 2022 18:03
-
-
Save krzyzanowskim/057676af670f06fa6061473ac28a6c58 to your computer and use it in GitHub Desktop.
NSRange TextKit2 helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSRange { | |
static let notFound = NSRange(location: NSNotFound, length: 0) | |
var isEmpty: Bool { | |
length == 0 | |
} | |
init(_ textRange: NSTextRange, in textContentManager: NSTextContentManager) { | |
let offset = textContentManager.offset(from: textContentManager.documentRange.location, to: textRange.location) | |
let length = textContentManager.offset(from: textRange.location, to: textRange.endLocation) | |
self.init(location: offset, length: length) | |
} | |
init(_ textLocation: NSTextLocation, in textContentManager: NSTextContentManager) { | |
let offset = textContentManager.offset(from: textContentManager.documentRange.location, to: textLocation) | |
self.init(location: offset, length: 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment