Col-E / Col-E/BentoFX

addContainer(int index, DockContainer)` ignores the index for the model list, desyncing it from `getItems()

Open Beginner friendly
#44 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
49
Forks
6
PR merge metrics
No merged PRs in 30d

Description

`DockContainerBranch.addContainer(int index, DockContainer container)` inserts the region at `index`
but appends the container to the model list:

```java
childContainers.add(container); // appended, index ignored
container.setParentContainer(this);
getItems().add(index, container.asRegion()); // inserted at index
```

Any call with `index != childContainers.size()` therefore leaves `getChildContainers()` and
`getItems()` in different orders. Every method that looks a child up in one list and writes to the
other by that index then addresses the wrong child — `replaceContainer`, `setContainerSizePx0`,
`setContainerResizable` and `setContainerCollapsed` all do exactly that.

### Reproduction

No stage or scene needed (JavaFX toolkit started only because the containers are Nodes):

```java
Bento bento = new Bento();
DockBuilding building = bento.dockBuilding();

DockContainerRootBranch root = building.root("root");
root.setOrientation(Orientation.HORIZONTAL);

DockContainerBranch center = building.branch("center");
root.addContainer(center);

DockContainerBranch sidebar = building.branch("sidebar");
root.addContainer(0, sidebar); // intent: sidebar left of center

// model = [center, sidebar]
// visual = [sidebar, center] // <-- already out of order

DockContainerLeaf a = building.leaf("a");
DockContainerLeaf c = building.leaf("c");
sidebar.addContainers(a, c);
sidebar.removeContainer(c); // sidebar prunes to one child
```

The prune calls `root.replaceContainer(sidebar, a)`, which takes `i = childContainers.indexOf(sidebar) = 1`
and then does `getItems().set(1, a.asRegion())` — but index 1 of `getItems()` is **center**.

Observed after the prune:

```
model = [center, a]
visual = [sidebar, a]
```

`center` and everything docked inside it is silently detached from the scene graph, while `sidebar`
stays on screen despite no longer being in the model. In our application that surfaced as the entire
editor area disappearing, and a user could trigger it by dragging alone.

### Expected

`getChildContainers()` and `getItems()` stay in the same order, so `addContainer(0, x)` puts `x`
first in both.

### Suggested fix

```java
childContainers.add(index, container);
```

### Version

0.16.0, and the code is unchanged on `master` as of today.

Contributor guide

Open the contributing guide

Research direction

Start at DockContainerBranch.addContainer(int index, DockContainer container), comparing updates to childContainers and getItems(). Reproduce the ordering mismatch with the JavaFX Bento, root, center, and sidebar sequence from the issue. Done means indexed insertion keeps both lists aligned and the described prune operation no longer detaches the wrong container.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.