Skip to content

fix(dockview-core): recompute target location after popout single-panel move (#1004)#1287

Merged
mathuo merged 1 commit into
masterfrom
fix/1004-popout-single-panel-reinsert
May 16, 2026
Merged

fix(dockview-core): recompute target location after popout single-panel move (#1004)#1287
mathuo merged 1 commit into
masterfrom
fix/1004-popout-single-panel-reinsert

Conversation

@mathuo
Copy link
Copy Markdown
Owner

@mathuo mathuo commented May 16, 2026

Summary

Fixes #1004.

When a single-panel popout window's panel was dragged back into the main dock at an extremity drop target (left/right/top/bottom of a neighbor group), the panel either landed at the wrong grid position or threw Invalid index at the far edge, losing the panel.

Root cause — popping out a single-panel group leaves an empty, invisible reference group in the main grid. The popout branch of moveGroupOrPanel (packages/dockview-core/src/dockview/dockviewComponent.ts) computed targetLocation before removing the popout group; that removal cascades through doRemoveGroup to delete the empty reference group too, shifting every following grid index down by one. The stale targetLocation was then passed to createGroupAtLocation, producing the wrong index (or a BranchNode.addChild: Invalid index throw at the far edge — matching the reporter's stack trace exactly).

Fix — recompute targetLocation from destinationGroup.element after doRemoveGroup(sourceGroup), mirroring the existing pattern a few lines below in the grid-source branch (// after deleting the group we need to re-evaulate the ref location).

Test plan

  • New regression test: issue #1004: panel from single-panel popout lands at correct index past original slot — drops the panel right of panel_3 (the neighbor following the original popout slot) and asserts grid order [panel_1, panel_3, panel_2, panel_4]. Confirmed to fail on the unpatched code with the panel ending up at the far right.
  • New regression test: issue #1004: panel from single-panel popout dropped past far edge does not throw — drops past the right-most neighbor. Confirmed to throw Invalid index at BranchNode.addChild on the unpatched code (matches reporter's stack trace).
  • Full popout group describe block passes (25 tests).
  • Full dockviewComponent.spec.ts suite: 195 passing on this branch vs. 193 on master (the +2 are the new tests). The 1 unrelated pre-existing failure (issue 1020) fails identically on master.

🤖 Generated with Claude Code

…el move (#1004)

When a single-panel popout group is dragged back into the dock as a panel
(not as the whole group), removing the popout group can cascade-remove
the empty reference group it left behind in the main grid. The popout
branch of moveGroupOrPanel was computing the destination grid location
before that cascade-removal, so the index was off by one for any drop
target after the original slot — and at the far edge it threw
"Invalid index" from BranchNode.addChild, losing the panel.

Recompute targetLocation from destinationGroup.element after the source
group is removed, mirroring the existing pattern at the grid-source path
in the same function.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@mathuo mathuo merged commit bce438f into master May 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-panel Popout drags back into the dock at wrong position, causing IndexOutOfBounds

1 participant