@@ -39,7 +39,23 @@ extension FoldingRibbonView {
3939 }
4040 let textRange = rangeStart. range. location..< rangeEnd. range. upperBound
4141
42+ let folds = getDrawingFolds ( forTextRange: textRange)
43+ for fold in folds {
44+ drawFoldMarker (
45+ fold,
46+ in: context,
47+ using: layoutManager
48+ )
49+ }
50+
51+ context. restoreGState ( )
52+ }
53+
54+ private func getDrawingFolds( forTextRange textRange: Range < Int > ) -> [ FoldRange ] {
4255 var folds = model? . getFolds ( in: textRange) ?? [ ]
56+
57+ // Add in some fake depths, we can draw these underneath the rest of the folds to make it look like it's
58+ // continuous
4359 if let minimumDepth = folds. min ( by: { $0. depth < $1. depth } ) ? . depth {
4460 for depth in ( 1 ..< minimumDepth) . reversed ( ) {
4561 folds. insert (
@@ -53,16 +69,8 @@ extension FoldingRibbonView {
5369 )
5470 }
5571 }
56- for (idx, fold) in folds. enumerated ( ) {
57- drawFoldMarker (
58- fold,
59- isFirst: idx == 0 ,
60- in: context,
61- using: layoutManager
62- )
63- }
6472
65- context . restoreGState ( )
73+ return folds
6674 }
6775
6876 /// Draw a single fold marker for a fold.
@@ -77,12 +85,11 @@ extension FoldingRibbonView {
7785 /// - layoutManager: A layout manager used to retrieve position information for lines.
7886 private func drawFoldMarker(
7987 _ fold: FoldRange ,
80- isFirst: Bool ,
8188 in context: CGContext ,
8289 using layoutManager: TextLayoutManager
8390 ) {
8491 guard let minYPosition = layoutManager. textLineForOffset ( fold. range. lowerBound) ? . yPos,
85- let maxPosition = layoutManager. textLineForOffset ( fold. range. upperBound - 1 ) else {
92+ let maxPosition = layoutManager. textLineForOffset ( fold. range. upperBound) else {
8693 return
8794 }
8895
@@ -101,7 +108,6 @@ extension FoldingRibbonView {
101108 } else {
102109 drawNestedFold (
103110 fold: fold,
104- isFirst: isFirst,
105111 minYPosition: minYPosition,
106112 maxYPosition: maxYPosition,
107113 in: context
@@ -190,7 +196,6 @@ extension FoldingRibbonView {
190196
191197 private func drawNestedFold(
192198 fold: FoldRange ,
193- isFirst: Bool ,
194199 minYPosition: CGFloat ,
195200 maxYPosition: CGFloat ,
196201 in context: CGContext
@@ -201,16 +206,8 @@ extension FoldingRibbonView {
201206 let roundedRect = NSBezierPath ( roundedRect: plainRect, xRadius: 3.5 , yRadius: 3.5 )
202207
203208 context. setFillColor ( markerColor)
204-
205- // if isFirst {
206- // for _ in 0..<fold.depth {
207- // context.addPath(roundedRect.cgPathFallback)
208- // context.drawPath(using: .fill)
209- // }
210- // } else {
211- context. addPath ( roundedRect. cgPathFallback)
212- context. drawPath ( using: . fill)
213- // }
209+ context. addPath ( roundedRect. cgPathFallback)
210+ context. drawPath ( using: . fill)
214211
215212 // Add small white line if we're overlapping with other markers
216213 if fold. depth != 0 {
@@ -221,6 +218,7 @@ extension FoldingRibbonView {
221218 in: context
222219 )
223220 }
221+
224222 context. restoreGState ( )
225223 }
226224
0 commit comments