CPSplitView: Update ratios and dividers when restoring autosaved state

Previously, restoration set only subview frames, leaving ratios from
the prior layout intact so a subsequent -adjustSubviews resized
subviews back to that layout and dividers remained unmoved until the
next layout pass. Restoration now updates the ratios and lays out the
split view so later resizes preserve the restored sizes.
This commit is contained in:
David Richardson committed 2026-11-23 16:39:22 -06:00
1 parent 92bf1b23de
commit b3fe257767
2 files changed
+34

No files matched your search

+11
View File
@@ -144,6 +144,17 @@
[_dividerSubviews[i] setFrameSize:size];
}
/*
The restored sizes become the ratios for later resizes, and the dividers move to the
restored positions.
2026-11-23: the restore set the subview frames only. The ratios stayed those of the
layout before the restore, so the next adjustSubviews resized the subviews back to
that layout. The dividers stayed in place until the next layout pass.
*/
[self _updateRatios];
[self _layoutSubviewsInEffectiveAppearance];
_shouldAutosave = YES;
}
}
+23
View File
@@ -384,6 +384,29 @@
[self assert:140 equals:CGRectGetWidth([viewA frame]) message:@"the divider position is restored"];
}
/*
A restored layout is the layout that later resizes keep: the next adjustSubviews leaves the
restored sizes in place, and the divider is at the restored position.
*/
- (void)testAutosaveRestoredSizesSurviveTheNextAdjustment
{
[self useAutosaveStore];
[splitView setAutosaveName:@"CPSplitViewInteractionTest.Ratios"];
[self dragDivider:0 toX:140];
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
[self setUp];
[splitView setAutosaveName:@"CPSplitViewInteractionTest.Ratios"];
[splitView _restoreFromAutosave];
[self assert:140 equals:CGRectGetMinX([splitView rectOfDividerAtIndex:0]) message:@"the divider is at the restored position"];
[splitView adjustSubviews];
[self assert:140 equals:CGRectGetWidth([viewA frame]) message:@"the restored size survives adjustSubviews"];
[self assert:140 equals:CGRectGetMinX([splitView rectOfDividerAtIndex:0]) message:@"the divider stays at the restored position"];
}
/*
Saved state belongs to the subviews it was saved for. A split view that has gained a subview
since the save keeps its current layout.