@@ -269,8 +269,8 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
269269 // If the element target section is recorded as insertion, record its element path as deletion.
270270 if let targetElementPath = sourceElementTraces [ sourceElementPath] . reference,
271271 case . some = sectionResult. metadata. targetReferences [ targetElementPath. section] {
272- let sourceElement = contiguousSourceSections [ sourceElementPath ]
273- firstStageElements. append ( sourceElement )
272+ let targetElement = contiguousTargetSections [ targetElementPath ]
273+ firstStageElements. append ( targetElement )
274274 continue
275275 }
276276
@@ -322,10 +322,10 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
322322 sourceElementTraces [ sourceElementPath] . isTracked = true
323323
324324 let sourceElement = contiguousSourceSections [ sourceElementPath]
325- thirdStageElements. append ( sourceElement )
325+ thirdStageElements. append ( targetElement )
326326
327327 if !targetElement. isContentEqual ( to: sourceElement) {
328- elementUpdated. append ( targetElementPath )
328+ elementUpdated. append ( sourceElementPath )
329329 }
330330
331331 if sourceElementPath. section != sourceSectionIndex || sourceElementPath. element != untrackedSourceIndex {
@@ -345,17 +345,19 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
345345 // - Includes:
346346 // - section deletes
347347 // - element deletes
348- if !sectionResult. deleted. isEmpty || !elementDeleted. isEmpty {
348+ // - element updates
349+ if !sectionResult. deleted. isEmpty || !elementDeleted. isEmpty || !elementUpdated. isEmpty {
349350 changesets. append (
350351 Changeset (
351352 data: Collection ( firstStageSections) ,
352353 sectionDeleted: sectionResult. deleted,
353- elementDeleted: elementDeleted
354+ elementDeleted: elementDeleted,
355+ elementUpdated: elementUpdated
354356 )
355357 )
356358 }
357359
358- // The 2st stage changeset.
360+ // The 2nd stage changeset.
359361 // - Includes:
360362 // - section inserts
361363 // - section moves
@@ -369,7 +371,7 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
369371 )
370372 }
371373
372- // The 3st stage changeset.
374+ // The 3rd stage changeset.
373375 // - Includes:
374376 // - element inserts
375377 // - element moves
@@ -383,16 +385,14 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C
383385 )
384386 }
385387
386- // The 3st stage changeset.
388+ // The 4th stage changeset.
387389 // - Includes:
388390 // - section updates
389- // - element updates
390- if !sectionResult. updated. isEmpty || !elementUpdated. isEmpty {
391+ if !sectionResult. updated. isEmpty {
391392 changesets. append (
392393 Changeset (
393394 data: target,
394- sectionUpdated: sectionResult. updated,
395- elementUpdated: elementUpdated
395+ sectionUpdated: sectionResult. updated
396396 )
397397 )
398398 }
0 commit comments