| 260 | } |
| 261 | |
| 262 | export class SyncedDiffIter implements IIterator<DiffIterValue> { |
| 263 | static cmp( |
| 264 | a: DiffIterValue, |
| 265 | b: DiffIterValue, |
| 266 | offsetA: number, |
| 267 | offsetB: number, |
| 268 | ) { |
| 269 | if (a === undefined && b === undefined) { |
| 270 | return 0; |
| 271 | } else if (a === undefined) { |
| 272 | return 1; |
| 273 | } else if (b === undefined) { |
| 274 | return -1; |
| 275 | } |
| 276 | let lineA = a.range.from.line + (a.isAddition ? offsetA : 0); |
| 277 | let lineB = b.range.from.line + (b.isAddition ? offsetB : 0); |
| 278 | if (lineA < lineB || a.range.from.column < b.range.from.column) { |
| 279 | return -1; |
| 280 | } else if (lineA > lineB || a.range.from.column > b.range.from.column) { |
| 281 | return 1; |
| 282 | } else { |
| 283 | return 0; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | constructor(models: (IStringDiffModel | null)[]) { |
| 288 | this.models = []; |
| 289 | this.iterators = []; |
| 290 | this.values = []; |
| 291 | this.offsets = []; |
| 292 | // Set up iterator and dummy chunkers for other models |
| 293 | for (let m of models) { |
| 294 | if (m === null) { |
| 295 | continue; |
| 296 | } |
| 297 | this.models.push(m); |
| 298 | let it = m.iterateDiffs(); |
| 299 | this.iterators.push(it); |
| 300 | this.offsets.push(0); |
| 301 | this.values.push(it.next()); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | next(): DiffIterValue { |
| 306 | // Compare in base index to see which diff is next |
| 307 | let i = 0; |
| 308 | for (let j = 1; j < this.values.length; ++j) { |
| 309 | if ( |
| 310 | 0 > |
| 311 | SyncedDiffIter.cmp( |
| 312 | this.values[j], |
| 313 | this.values[i], |
| 314 | this.iterators[j].editOffset, |
| 315 | this.iterators[i].editOffset, |
| 316 | ) |
| 317 | ) { |
| 318 | i = j; |
| 319 | } |
nothing calls this directly
no outgoing calls
no test coverage detected