CPSplitView: Restore subview management after replacing unarranged subviews

-replaceSubview:with: previously disabled subview management and returned
early when the replaced subview was unarranged, leaving management off.
Subsequent -addSubview: calls did not arrange new subviews, and

-removeFromSuperview did not remove views from arranged subviews.
Subview management is now re-enabled across all return paths.
This commit is contained in:
David Richardson committed 2026-11-24 11:20:23 -06:00
1 parent 709d8fa904
commit cc2766c2f0
2 files changed
+24 -5

No files matched your search

+11 -5
View File
@@ -557,11 +557,17 @@ var CPThemeStatesForSplitViewDivider = @[@"dummy one as CPSplitViewDividerStyle
[super replaceSubview:aSubview with:aView];
if (arrangedIndex < 0)
return;
[_arrangedSubviews replaceObjectAtIndex:arrangedIndex withObject:aView];
[_realSubviews replaceObjectAtIndex:realIndex withObject:aView];
/*
2026-11-24: for a subview that was not arranged, the method returned here and left
subview management turned off. After that, -addSubview: no longer arranged a new
subview and -removeFromSuperview no longer removed an arranged subview from the
arranged subviews.
*/
if (arrangedIndex >= 0)
{
[_arrangedSubviews replaceObjectAtIndex:arrangedIndex withObject:aView];
[_realSubviews replaceObjectAtIndex:realIndex withObject:aView];
}
_subviewsManagementDisabled = NO;
}
+13
View File
@@ -820,6 +820,19 @@
[self assert:[first, second] equals:[otherSplitView arrangedSubviews] message:@"both subviews are arranged, in order"];
}
- (void)testReplacingASubviewThatIsNotArrangedKeepsSubviewManagement
{
var extra = [[CPView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)],
replacement = [[CPView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
[splitView setArrangesAllSubviews:NO];
[splitView addSubview:extra];
[splitView replaceSubview:extra with:replacement];
[viewB removeFromSuperview];
[self assert:[viewA] equals:[splitView arrangedSubviews] message:@"a removed subview leaves the arranged subviews"];
}
// MARK: - Archiving
- (void)testArchivingKeepsTheLayout