diff --git a/Sources/WireGuardApp/UI/macOS/View/ConfTextStorage.swift b/Sources/WireGuardApp/UI/macOS/View/ConfTextStorage.swift index 0e63b73..d050630 100644 --- a/Sources/WireGuardApp/UI/macOS/View/ConfTextStorage.swift +++ b/Sources/WireGuardApp/UI/macOS/View/ConfTextStorage.swift @@ -67,7 +67,7 @@ class ConfTextStorage: NSTextStorage { override func replaceCharacters(in range: NSRange, with str: String) { beginEditing() backingStore.replaceCharacters(in: range, with: str) - edited(.editedCharacters, range: range, changeInLength: str.count - range.length) + edited(.editedCharacters, range: range, changeInLength: str.utf16.count - range.length) endEditing() } @@ -94,6 +94,7 @@ class ConfTextStorage: NSTextStorage { func evaluateExcludePrivateIPs(highlightSpans: UnsafePointer) { var spans = highlightSpans + let string = backingStore.string enum FieldType: String { case dns case allowedips @@ -102,7 +103,7 @@ class ConfTextStorage: NSTextStorage { resetLastPeer() while spans.pointee.type != HighlightEnd { let span = spans.pointee - var substring = backingStore.attributedSubstring(from: NSRange(location: span.start, length: span.len)).string.lowercased() + var substring = String(string.substring(higlightSpan: span)).lowercased() if span.type == HighlightError { resetLastPeer() @@ -123,8 +124,9 @@ class ConfTextStorage: NSTextStorage { let next = spans.successor() let nextnext = next.successor() if next.pointee.type == HighlightDelimiter && nextnext.pointee.type == HighlightCidr { - substring += backingStore.attributedSubstring(from: NSRange(location: next.pointee.start, length: next.pointee.len)).string + - backingStore.attributedSubstring(from: NSRange(location: nextnext.pointee.start, length: nextnext.pointee.len)).string + let delimiter = string.substring(higlightSpan: next.pointee) + let cidr = string.substring(higlightSpan: nextnext.pointee) + substring += delimiter + cidr } lastOnePeerAllowedIPs.append(substring) } else if span.type == HighlightPublicKey { @@ -139,7 +141,8 @@ class ConfTextStorage: NSTextStorage { hasError = false privateKeyString = nil - let fullTextRange = NSRange(location: 0, length: (backingStore.string as NSString).length) + let string = backingStore.string + let fullTextRange = NSRange(.. Substring { + let startIndex = self.utf8.index(self.utf8.startIndex, offsetBy: span.start) + let endIndex = self.utf8.index(startIndex, offsetBy: span.len) + + return self[startIndex..