@@ -149,15 +149,24 @@ private func makeDiffAttributes(
149149private func diffRowRect(
150150 index: Int ,
151151 rowCount: Int ,
152- contentHeight : CGFloat ,
153- bounds : CGRect
152+ bounds : CGRect ,
153+ theme : MarkdownTheme
154154) -> CGRect {
155- let lineHeight = contentHeight / CGFloat( max ( rowCount, 1 ) )
155+ #if canImport(UIKit)
156+ let lineHeight = theme. fonts. code. lineHeight
157+ #elseif canImport(AppKit)
158+ let font = theme. fonts. code
159+ let lineHeight = font. ascender + abs( font. descender) + font. leading
160+ #endif
161+
162+ let lineSpacing = CodeViewConfiguration . codeLineSpacing
163+ let rowAdvance = lineHeight + lineSpacing
164+ let isLastRow = index == max ( rowCount - 1 , 0 )
156165 return CGRect (
157166 x: bounds. minX,
158- y: DiffViewConfiguration . verticalPadding + CGFloat( index) * lineHeight ,
167+ y: DiffViewConfiguration . verticalPadding + CGFloat( index) * rowAdvance ,
159168 width: bounds. width,
160- height: lineHeight
169+ height: lineHeight + ( isLastRow ? 0 : lineSpacing )
161170 )
162171}
163172
@@ -264,12 +273,7 @@ private func unifiedContentRowBackgroundColor(
264273 for kind: DiffPresentation . UnifiedRow . Kind ,
265274 theme: MarkdownTheme
266275) -> PlatformColor ? {
267- switch kind {
268- case . removed, . added:
269- return nil
270- case . fileHeader, . fileMetadata, . hunkHeader, . context, . annotation, . collapsedContext:
271- return unifiedRowBackgroundColor ( for: kind, theme: theme)
272- }
276+ unifiedRowBackgroundColor ( for: kind, theme: theme)
273277}
274278
275279private func unifiedEmphasisColor(
@@ -287,46 +291,6 @@ private func unifiedEmphasisColor(
287291 }
288292}
289293
290- private func unifiedLineBackgroundColor(
291- for kind: DiffPresentation . UnifiedRow . Kind ,
292- theme: MarkdownTheme
293- ) -> PlatformColor ? {
294- guard showsLineChangeHighlights ( in: theme) else { return nil }
295- switch kind {
296- case . removed:
297- return theme. diff. removedLineBackground
298- case . added:
299- return theme. diff. addedLineBackground
300- case . fileHeader, . fileMetadata, . hunkHeader, . context, . annotation, . collapsedContext:
301- return nil
302- }
303- }
304-
305- private func makeFullWidthLineBackgroundAction(
306- color: PlatformColor
307- ) -> LTXLineDrawingAction {
308- LTXLineDrawingAction { context, line, lineOrigin in
309- var ascent : CGFloat = 0
310- var descent : CGFloat = 0
311- var leading : CGFloat = 0
312- CTLineGetTypographicBounds ( line, & ascent, & descent, & leading)
313-
314- let lineSpacing = CodeViewConfiguration . codeLineSpacing
315- let clipBounds = context. boundingBoxOfClipPath
316- let rect = CGRect (
317- x: clipBounds. minX,
318- y: lineOrigin. y - descent - lineSpacing / 2 ,
319- width: clipBounds. width,
320- height: ascent + descent + leading + lineSpacing
321- )
322-
323- context. saveGState ( )
324- context. setFillColor ( color. cgColor)
325- context. fill ( rect)
326- context. restoreGState ( )
327- }
328- }
329-
330294private func sideBySideRowTextColor(
331295 for kind: DiffPresentation . SideBySideRow . Kind ,
332296 theme: MarkdownTheme
@@ -633,16 +597,11 @@ private func makeUnifiedAttributedText(
633597
634598 for (index, row) in rows. enumerated ( ) {
635599 let rowStart = result. length
636- var attributes = makeDiffAttributes (
600+ let attributes = makeDiffAttributes (
637601 font: font,
638602 color: unifiedTextColor ( for: row. kind, theme: theme) ,
639603 paragraphStyle: paragraphStyle
640604 )
641- if let lineBackgroundColor = unifiedLineBackgroundColor ( for: row. kind, theme: theme) {
642- attributes [ . ltxLineDrawingCallback] = makeFullWidthLineBackgroundAction (
643- color: lineBackgroundColor
644- )
645- }
646605 result. append ( . init( string: row. text, attributes: attributes) )
647606
648607 let rowLength = row. text. utf16. count
@@ -1125,8 +1084,8 @@ private func makeSideBySideAttributedText(
11251084 let rect = diffRowRect (
11261085 index: index,
11271086 rowCount: rows. count,
1128- contentHeight : contentHeight ,
1129- bounds : bounds
1087+ bounds : bounds ,
1088+ theme : theme
11301089 )
11311090
11321091 if let fillColor = unifiedContentRowBackgroundColor ( for: row. kind, theme: theme) {
@@ -1151,8 +1110,8 @@ private func makeSideBySideAttributedText(
11511110 let rect = diffRowRect (
11521111 index: index,
11531112 rowCount: rows. count,
1154- contentHeight : contentHeight ,
1155- bounds : bounds
1113+ bounds : bounds ,
1114+ theme : theme
11561115 )
11571116
11581117 switch row. kind {
@@ -1256,8 +1215,8 @@ private func makeSideBySideAttributedText(
12561215 let rect = diffRowRect (
12571216 index: index,
12581217 rowCount: rows. count,
1259- contentHeight : contentHeight ,
1260- bounds : bounds
1218+ bounds : bounds ,
1219+ theme : theme
12611220 )
12621221
12631222 if let fillColor = unifiedRowBackgroundColor ( for: row. kind, theme: theme) {
@@ -1296,8 +1255,8 @@ private func makeSideBySideAttributedText(
12961255 let rect = diffRowRect (
12971256 index: index,
12981257 rowCount: rows. count,
1299- contentHeight : contentHeight ,
1300- bounds : bounds
1258+ bounds : bounds ,
1259+ theme : theme
13011260 )
13021261
13031262 let rowRects = diffGutterRowRects ( for: metrics, rowRect: rect)
@@ -1814,8 +1773,8 @@ private func makeSideBySideAttributedText(
18141773 let rect = diffRowRect (
18151774 index: index,
18161775 rowCount: rows. count,
1817- contentHeight : contentHeight ,
1818- bounds : bounds
1776+ bounds : bounds ,
1777+ theme : theme
18191778 )
18201779
18211780 if let fillColor = unifiedContentRowBackgroundColor ( for: row. kind, theme: theme) {
@@ -1840,8 +1799,8 @@ private func makeSideBySideAttributedText(
18401799 let rect = diffRowRect (
18411800 index: index,
18421801 rowCount: rows. count,
1843- contentHeight : contentHeight ,
1844- bounds : bounds
1802+ bounds : bounds ,
1803+ theme : theme
18451804 )
18461805
18471806 switch row. kind {
@@ -1938,8 +1897,8 @@ private func makeSideBySideAttributedText(
19381897 let rect = diffRowRect (
19391898 index: index,
19401899 rowCount: rows. count,
1941- contentHeight : contentHeight ,
1942- bounds : bounds
1900+ bounds : bounds ,
1901+ theme : theme
19431902 )
19441903
19451904 if let fillColor = unifiedRowBackgroundColor ( for: row. kind, theme: theme) {
@@ -1978,8 +1937,8 @@ private func makeSideBySideAttributedText(
19781937 let rect = diffRowRect (
19791938 index: index,
19801939 rowCount: rows. count,
1981- contentHeight : contentHeight ,
1982- bounds : bounds
1940+ bounds : bounds ,
1941+ theme : theme
19831942 )
19841943
19851944 let rowRects = diffGutterRowRects ( for: metrics, rowRect: rect)
0 commit comments