Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewContainerLayout: remove moveWidget override #11576

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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