@@ -12,6 +12,7 @@ struct _CodeBlock: View {
1212 let commonPrecedingSpaceCount : Int
1313 let highlightedCode : AttributedString
1414 let colorScheme : ColorScheme
15+ let droppingLeadingSpaces : Bool
1516
1617 /// Create a text edit view with a certain text that uses a certain options.
1718 /// - Parameters:
@@ -24,11 +25,13 @@ struct _CodeBlock: View {
2425 firstLinePrecedingSpaceCount: Int ,
2526 colorScheme: ColorScheme ,
2627 fontSize: Double ,
28+ droppingLeadingSpaces: Bool ,
2729 selection: Binding < NSRange ? > = . constant( nil )
2830 ) {
2931 _selection = selection
3032 self . fontSize = fontSize
3133 self . colorScheme = colorScheme
34+ self . droppingLeadingSpaces = droppingLeadingSpaces
3235
3336 let padding = firstLinePrecedingSpaceCount > 0
3437 ? String ( repeating: " " , count: firstLinePrecedingSpaceCount)
@@ -37,7 +40,8 @@ struct _CodeBlock: View {
3740 code: padding + code,
3841 language: language,
3942 colorScheme: colorScheme,
40- fontSize: fontSize
43+ fontSize: fontSize,
44+ droppingLeadingSpaces: droppingLeadingSpaces
4145 )
4246 commonPrecedingSpaceCount = result. commonLeadingSpaceCount
4347 highlightedCode = result. code
@@ -65,14 +69,14 @@ struct _CodeBlock: View {
6569 code: String ,
6670 language: String ,
6771 colorScheme: ColorScheme ,
68- fontSize: Double
72+ fontSize: Double ,
73+ droppingLeadingSpaces: Bool
6974 ) -> ( code: AttributedString , commonLeadingSpaceCount: Int ) {
7075 let ( lines, commonLeadingSpaceCount) = highlighted (
7176 code: code,
7277 language: language,
7378 brightMode: colorScheme != . dark,
74- droppingLeadingSpaces: UserDefaults . shared
75- . value ( for: \. hideCommonPrecedingSpacesInSuggestion) ,
79+ droppingLeadingSpaces: droppingLeadingSpaces,
7680 fontSize: fontSize,
7781 replaceSpacesWithMiddleDots: false
7882 )
@@ -142,7 +146,7 @@ private struct _CodeBlockRepresentable: NSViewRepresentable {
142146 context. coordinator. parent = self
143147
144148 let textView = scrollView. documentView as! STTextViewFrameObservable
145-
149+
146150 textView. onHeightChange = onHeightChange
147151 textView. showsInvisibleCharacters = true
148152 textView. textContainer. lineBreakMode = . byCharWrapping
@@ -241,7 +245,10 @@ private class STTextViewFrameObservable: STTextView {
241245 var onHeightChange : ( ( Double ) -> Void ) ?
242246 func recalculateSize( ) {
243247 var maxY = 0 as Double
244- textLayoutManager. enumerateTextLayoutFragments ( in: textLayoutManager. documentRange, options: [ . ensuresLayout] ) { fragment in
248+ textLayoutManager. enumerateTextLayoutFragments (
249+ in: textLayoutManager. documentRange,
250+ options: [ . ensuresLayout]
251+ ) { fragment in
245252 print ( fragment. layoutFragmentFrame)
246253 maxY = max ( maxY, fragment. layoutFragmentFrame. maxY)
247254 return true
@@ -287,3 +294,4 @@ private final class ColumnRuler: NSRulerView {
287294 ] )
288295 }
289296}
297+
0 commit comments