@@ -27,14 +27,18 @@ import Foundation
2727
2828extension String {
2929 /// Find the range of a substring (case-insensitive).
30- fileprivate func rangeOfSubstring( _ substring: String ) -> Range < String . Index > ? {
30+ fileprivate func rangeOfSubstring( _ substring: String ) -> Range < String . Index > ?
31+ {
3132 #if canImport(FoundationEssentials)
3233 // FoundationEssentials doesn't include String.range(of:)
3334 // Use the existing firstMatch implementation from CompletionsGenerator.swift
3435 let lowercased = self . lowercased ( )
3536 let lowercasedSubstring = substring. lowercased ( )
3637
37- guard let match = lowercased. firstMatch ( of: lowercasedSubstring, at: lowercased. startIndex) else {
38+ guard
39+ let match = lowercased. firstMatch (
40+ of: lowercasedSubstring, at: lowercased. startIndex)
41+ else {
3842 return nil
3943 }
4044
@@ -75,10 +79,17 @@ enum ANSICode {
7579 let searchRange = searchStartIndex..< text. endIndex
7680 let lowercasedSearchRange = String ( lowercasedText [ searchRange] )
7781
78- if let matchRange = lowercasedSearchRange. rangeOfSubstring ( lowercasedTerm) {
82+ if let matchRange = lowercasedSearchRange. rangeOfSubstring ( lowercasedTerm)
83+ {
7984 // Convert the match range from lowercased text to original text
80- let matchStart = text. index ( searchStartIndex, offsetBy: lowercasedSearchRange. distance ( from: lowercasedSearchRange. startIndex, to: matchRange. lowerBound) )
81- let matchEnd = text. index ( searchStartIndex, offsetBy: lowercasedSearchRange. distance ( from: lowercasedSearchRange. startIndex, to: matchRange. upperBound) )
85+ let matchStart = text. index (
86+ searchStartIndex,
87+ offsetBy: lowercasedSearchRange. distance (
88+ from: lowercasedSearchRange. startIndex, to: matchRange. lowerBound) )
89+ let matchEnd = text. index (
90+ searchStartIndex,
91+ offsetBy: lowercasedSearchRange. distance (
92+ from: lowercasedSearchRange. startIndex, to: matchRange. upperBound) )
8293
8394 // Add text before the match
8495 result += text [ searchStartIndex..< matchStart]
@@ -413,9 +424,7 @@ struct CommandSearcher {
413424 }
414425
415426 // Replace newlines with spaces for display
416- snippet = snippet. replacingOccurrences ( of: " \n " , with: " " )
417- . replacingOccurrences ( of: " \\ s+ " , with: " " , options: String . CompareOptions. regularExpression)
418-
427+ snippet = snippet. replacing ( " \n " , with: " " )
419428 return snippet
420429 }
421430
0 commit comments