Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop section moves if they are also deleted or inserted #577

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ This release closes the [3.0.0 milestone](https://github.com/Instagram/IGListKit

- Remove objects that return `nil` diff identifiers before updating. [Ryan Nystrom](https://github.com/rnystrom) [(af984ca)](https://github.com/Instagram/IGListKit/commit/af984ca81d4d8c4ba3012be1a45f69670a832ccf)

- Fix a potential crash when a section is moved and deleted at the same time. [Ryan Nystrom](https://github.com/rnystrom) [(#577)](https://github.com/Instagram/IGListKit/pull/577)

2.1.0
-----

Expand Down
5 changes: 3 additions & 2 deletions Source/Common/IGListBatchUpdateData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ - (instancetype)initWithInsertSections:(NSIndexSet *)insertSections
const NSInteger from = move.from;
const NSInteger to = move.to;

// if the move is already deleted or inserted, discard it and use delete+insert instead
// if the move is already deleted or inserted, discard it because count-changing operations must match
// with data source changes
if ([deleteSections containsIndex:from] || [insertSections containsIndex:to]) {
convertMoveToDeleteAndInsert(mMoveSections, move, mDeleteSections, mInsertSections);
[mMoveSections removeObject:move];
} else {
fromMap[from] = move;
toMap[to] = move;
Expand Down
14 changes: 14 additions & 0 deletions Tests/IGListBatchUpdateDataTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,18 @@ - (void)test_whenMovingIndexPaths_withSectionMoved_thatResultConvertsToDeletesAn
XCTAssertEqualObjects(result.insertSections, indexSet(@[@1]));
}

- (void)test_whenMovingSections_withMoveFromConflictWithDelete_thatResultDropsTheMove {
IGListBatchUpdateData *result = [[IGListBatchUpdateData alloc] initWithInsertSections:indexSet(@[])
deleteSections:indexSet(@[@2])
moveSections:[NSSet setWithArray:@[newMove(2, 6), newMove(0, 2)]]
insertIndexPaths:[NSSet new]
deleteIndexPaths:[NSSet new]
moveIndexPaths:[NSSet new]];
XCTAssertEqual(result.deleteSections.count, 1);
XCTAssertEqual(result.moveSections.count, 1);
XCTAssertEqual(result.insertSections.count, 0);
XCTAssertEqualObjects(result.deleteSections, indexSet(@[@2]));
XCTAssertEqualObjects(result.moveSections.anyObject, newMove(0, 2));
}

@end