Skip to content

Commit

Permalink
ViewContainerLayout: remove moveWidget override
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work committed Sep 6, 2022
1 parent af11fa0 commit a96e48a
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions packages/core/src/browser/view-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
// Reorder the parts according to the stored state
for (let index = 0; index < partStates.length; index++) {
const partState = partStates[index];
const currentIndex = this.getParts().findIndex(part => part.partId === partState.partId);
if (currentIndex > index) {
this.containerLayout.moveWidget(currentIndex, index, this.getParts()[currentIndex]);
const widget = this.getParts().find(part => part.partId === partState.partId);
if (widget) {
this.containerLayout.insertWidget(index, widget);
}
}

Expand All @@ -547,6 +547,7 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
// Restore part sizes
waitForRevealed(this).then(() => {
this.containerLayout.setPartSizes(partStates.map(partState => partState.relativeSize));
this.updateSplitterVisibility();
});
}

Expand Down Expand Up @@ -619,15 +620,16 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica

protected moveBefore(toMovedId: string, moveBeforeThisId: string): void {
const parts = this.getParts();
const toMoveIndex = parts.findIndex(part => part.id === toMovedId);
const moveBeforeThisIndex = parts.findIndex(part => part.id === moveBeforeThisId);
if (toMoveIndex >= 0 && moveBeforeThisIndex >= 0) {
this.containerLayout.moveWidget(toMoveIndex, moveBeforeThisIndex, parts[toMoveIndex]);
for (let index = Math.min(toMoveIndex, moveBeforeThisIndex); index < parts.length; index++) {
const indexToMove = parts.findIndex(part => part.id === toMovedId);
const targetIndex = parts.findIndex(part => part.id === moveBeforeThisId);
if (indexToMove >= 0 && targetIndex >= 0) {
this.containerLayout.insertWidget(targetIndex, parts[indexToMove]);
for (let index = Math.min(indexToMove, targetIndex); index < parts.length; index++) {
this.refreshMenu(parts[index]);
this.activate();
}
}
this.updateSplitterVisibility();
}

getTrackableWidgets(): Widget[] {
Expand Down Expand Up @@ -1339,22 +1341,6 @@ export class ViewContainerLayout extends SplitLayout {
}
}

override moveWidget(fromIndex: number, toIndex: number, widget: Widget): void {
const ref = this.widgets[toIndex < fromIndex ? toIndex : toIndex + 1];
super.moveWidget(fromIndex, toIndex, widget);
// Keep the order of `_widgets` array just as done before (by `super`) for the `_items` array -
// to prevent later bugs relying on index.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ArrayExt.move((this as any)._widgets, fromIndex, toIndex);
if (ref) {
this.parent!.node.insertBefore(this.handles[toIndex], ref.node);
} else {
this.parent!.node.appendChild(this.handles[toIndex]);
}
UnsafeWidgetUtilities.detach(widget);
UnsafeWidgetUtilities.attach(widget, this.parent!.node, this.handles[toIndex]);
}

getPartSize(part: ViewContainerPart): number | undefined {
if (part.collapsed || part.isHidden) {
return part.uncollapsedSize;
Expand Down

0 comments on commit a96e48a

Please sign in to comment.