@@ -9,6 +9,10 @@ import Pulse
9
9
import CoreData
10
10
import Combine
11
11
12
+ #if os(macOS)
13
+ import AppKit
14
+ #endif
15
+
12
16
@available ( iOS 16 , visionOS 1 , * )
13
17
package final class ConsoleSearchOccurrence : Identifiable , Equatable , Hashable {
14
18
package let id = ConsoleSearchOccurrenceId ( )
@@ -40,9 +44,33 @@ private let previewAttibutes = TextHelper().attributes(role: .body2, style: .mon
40
44
41
45
@available ( iOS 16 , visionOS 1 , * )
42
46
extension ConsoleSearchOccurrence {
43
- static func makePreview( for match: ConsoleSearchMatch , attributes customAttributes: [ NSAttributedString . Key : Any ] = [ : ] ) -> AttributedString {
47
+ package static func makePreview( for match: ConsoleSearchMatch , attributes customAttributes: [ NSAttributedString . Key : Any ] = [ : ] ) -> AttributedString {
48
+ let segments = makePreviewSegments ( for: match)
49
+
50
+ var attributes = AttributeContainer ( customAttributes)
51
+ #if os(macOS)
52
+ attributes. foregroundColor = . secondary
53
+ attributes. font = . callout
54
+ #endif
44
55
45
- let prefixStartIndex = match. line. index ( match. range. lowerBound, offsetBy: - 50 , limitedBy: match. line. startIndex) ?? match. line. startIndex
56
+ var middle = AttributedString ( segments [ 1 ] , attributes: attributes)
57
+ #if os(macOS)
58
+ middle. foregroundColor = . primary
59
+ middle. font = Font . callout. weight ( . semibold)
60
+ #else
61
+ middle. foregroundColor = . orange
62
+ #endif
63
+ return AttributedString ( segments [ 0 ] , attributes: attributes) + middle + AttributedString( segments [ 2 ] , attributes: attributes)
64
+ }
65
+
66
+ package static func makePreviewSegments( for match: ConsoleSearchMatch ) -> [ Substring ] {
67
+ let prefixOffset : Int
68
+ #if os(macOS)
69
+ prefixOffset = - 20
70
+ #else
71
+ prefixOffset = - 50
72
+ #endif
73
+ let prefixStartIndex = match. line. index ( match. range. lowerBound, offsetBy: prefixOffset, limitedBy: match. line. startIndex) ?? match. line. startIndex
46
74
let prefixRange = prefixStartIndex..< match. range. lowerBound
47
75
48
76
let suffixUpperBound = match. line. index ( match. range. upperBound, offsetBy: 200 , limitedBy: match. line. endIndex) ?? match. line. endIndex
@@ -62,11 +90,7 @@ extension ConsoleSearchOccurrence {
62
90
if isEllipsisNeeded {
63
91
prefix. insert ( " … " , at: prefix. startIndex)
64
92
}
65
-
66
- let attributes = AttributeContainer ( customAttributes)
67
- var middle = AttributedString ( match. line [ match. range] , attributes: attributes)
68
- middle. foregroundColor = . orange
69
- return AttributedString ( prefix, attributes: attributes) + middle + AttributedString( suffix, attributes: attributes)
93
+ return [ prefix, match. line [ match. range] , suffix]
70
94
}
71
95
}
72
96
0 commit comments