Skip to content

Commit ce31ec9

Browse files
authored
fix: allow JSON state updates to reset flex group sizes (#824)
Fixes #823
1 parent 33bb42e commit ce31ec9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/ui/side_panel.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export class SidePanelManager extends RefCounted {
263263
private registeredPanels = new Set<RegisteredSidePanel>();
264264
dragSource: DragSource | undefined;
265265
private layoutNeedsUpdate = false;
266+
private shouldResetFlexGroupSizes = false;
266267

267268
get visible() {
268269
return this.visibility.visible;
@@ -333,6 +334,17 @@ export class SidePanelManager extends RefCounted {
333334
this.dragSource = undefined;
334335
}
335336

337+
/**
338+
* Once a panel is added to a flex group, the panel no longer controls the
339+
* size of the flex group. This resets the flex group sizes so that
340+
* panels can set the size of the flex group. This is useful when
341+
* panel sizes are manually set from the JSON state.
342+
*/
343+
reset() {
344+
this.shouldResetFlexGroupSizes = true;
345+
this.invalidateLayout();
346+
}
347+
336348
private makeDropZone(
337349
side: Side,
338350
crossIndex: number,
@@ -460,6 +472,7 @@ export class SidePanelManager extends RefCounted {
460472
yield self.sides.bottom.outerDropZoneElement;
461473
}
462474
updateChildren(this.centerColumn, getColumnChildren());
475+
this.shouldResetFlexGroupSizes = false;
463476
}
464477

465478
private makeCrossGutter(side: Side, crossIndex: number) {
@@ -689,12 +702,11 @@ export class SidePanelManager extends RefCounted {
689702
}
690703
const oldLocation = cell.registeredPanel.location.value;
691704
if (oldLocation.visible) {
692-
flexGroup.crossSize = Math.max(
693-
minSize,
694-
flexGroup.crossSize === -1
705+
const suggestedSize =
706+
self.shouldResetFlexGroupSizes || flexGroup.crossSize === -1
695707
? oldLocation.size
696-
: flexGroup.crossSize,
697-
);
708+
: flexGroup.crossSize;
709+
flexGroup.crossSize = Math.max(minSize, suggestedSize);
698710
}
699711
if (
700712
oldLocation[crossKey] !== crossIndex ||

src/viewer.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ class TrackableViewerState extends CompoundTrackable {
355355
viewer.perspectiveViewBackgroundColor,
356356
);
357357
}
358+
359+
reset() {
360+
super.reset();
361+
this.viewer.sidePanelManager.reset();
362+
}
358363
}
359364

360365
export class Viewer extends RefCounted implements ViewerState {

0 commit comments

Comments
 (0)