mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
CPSplitView fix: Restore autosaved state only for the subviews it was saved for
The restore took one saved frame for each arranged subview and did not check the count. A split view with more subviews than at the save applied CGRectFromString(undefined) to the extra subviews. The restore now applies saved state only when the number of saved frames, and of saved collapsed flags, matches the number of arranged subviews; otherwise the split view keeps its current layout.
This commit is contained in:
1 parent
10e4497fa4
commit
92bf1b23de
2 files changed
+35
-1
No files matched your search
@@ -99,7 +99,15 @@
|
||||
frames = [userDefaults objectForKey:autosaveName],
|
||||
collapsed = [userDefaults objectForKey:autosaveCollapsedName];
|
||||
|
||||
if (frames)
|
||||
/*
|
||||
Saved state applies only to the subviews it was saved for. When the number of arranged
|
||||
subviews has changed since the save, the split view keeps its current layout.
|
||||
|
||||
2026-11-23: the restore took one saved frame for each arranged subview and did not
|
||||
check the count. A split view with more subviews than at the save applied
|
||||
CGRectFromString(undefined) to the extra subviews.
|
||||
*/
|
||||
if (frames && [frames count] === _arrangedSubviews.length && (!collapsed || [collapsed count] === [frames count]))
|
||||
{
|
||||
var dividerThickness = [self dividerThickness],
|
||||
position = 0;
|
||||
|
||||
@@ -384,6 +384,32 @@
|
||||
[self assert:140 equals:CGRectGetWidth([viewA frame]) message:@"the divider position is restored"];
|
||||
}
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
- (void)testAutosaveIgnoresStateSavedForADifferentNumberOfSubviews
|
||||
{
|
||||
[self useAutosaveStore];
|
||||
[splitView setAutosaveName:@"CPSplitViewInteractionTest.Count"];
|
||||
[self dragDivider:0 toX:140];
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
[self setUp];
|
||||
[splitView addArrangedSubview:[[CPView alloc] initWithFrame:CGRectMake(0, 0, 50, 100)]];
|
||||
[splitView adjustSubviews];
|
||||
|
||||
var framesBefore = [[splitView arrangedSubviews] valueForKey:@"frame"];
|
||||
|
||||
[splitView setAutosaveName:@"CPSplitViewInteractionTest.Count"];
|
||||
[splitView _restoreFromAutosave];
|
||||
|
||||
var framesAfter = [[splitView arrangedSubviews] valueForKey:@"frame"];
|
||||
|
||||
for (var i = 0; i < 3; i++)
|
||||
[self assertTrue:CGRectEqualToRect(framesBefore[i], framesAfter[i]) message:@"subview " + i + " keeps its frame"];
|
||||
}
|
||||
|
||||
/*
|
||||
AppKit saves whether each subview is collapsed, so a collapsed sidebar stays collapsed.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user