@@ -3,7 +3,7 @@ import SuggestionBasic
33
44public struct CodeDiff {
55 public init ( ) { }
6-
6+
77 public typealias LineDiff = CollectionDifference < String >
88
99 public struct SnippetDiff : Equatable {
@@ -23,6 +23,8 @@ public struct CodeDiff {
2323 }
2424
2525 public struct Section : Equatable {
26+ public var oldOffset : Int
27+ public var newOffset : Int
2628 public var oldSnippet : [ Line ]
2729 public var newSnippet : [ Line ]
2830
@@ -113,7 +115,12 @@ public struct CodeDiff {
113115 let insertionSection = insertions [ safe: sectionIndex]
114116
115117 // handle lines before sections
116- var beforeSection = SnippetDiff . Section ( oldSnippet: [ ] , newSnippet: [ ] )
118+ var beforeSection = SnippetDiff . Section (
119+ oldOffset: 0 ,
120+ newOffset: 0 ,
121+ oldSnippet: [ ] ,
122+ newSnippet: [ ]
123+ )
117124
118125 while oldLineIndex < ( removalSection? . offset ?? oldLines. endIndex) {
119126 if oldLineIndex < oldLines. endIndex {
@@ -140,7 +147,12 @@ public struct CodeDiff {
140147
141148 // handle lines inside sections
142149
143- var insideSection = SnippetDiff . Section ( oldSnippet: [ ] , newSnippet: [ ] )
150+ var insideSection = SnippetDiff . Section (
151+ oldOffset: removalSection? . offset ?? 0 ,
152+ newOffset: insertionSection? . offset ?? 0 ,
153+ oldSnippet: [ ] ,
154+ newSnippet: [ ]
155+ )
144156
145157 for i in 0 ..< max ( removalSection? . lines. count ?? 0 , insertionSection? . lines. count ?? 0 ) {
146158 let oldLine = removalSection? . lines [ safe: i]
@@ -247,7 +259,7 @@ extension CodeDiff {
247259 removalUnchangedGap = 0
248260 insertionUnchangedGap = 0
249261 }
250- } else if removalUnchangedGap > insertionUnchangedGap {
262+ } else if removalUnchangedGap > insertionUnchangedGap {
251263 // insert empty sections to removals
252264 if insertionUnchangedGap > 0 {
253265 let count = removalUnchangedGap - insertionUnchangedGap
0 commit comments