Skip to content

fix: clamp tab index in move_tab to prevent out-of-bounds insert#308

Open
enomado wants to merge 1 commit intoanhosh:mainfrom
enomado:fix/move-tab-index-out-of-bounds
Open

fix: clamp tab index in move_tab to prevent out-of-bounds insert#308
enomado wants to merge 1 commit intoanhosh:mainfrom
enomado:fix/move-tab-index-out-of-bounds

Conversation

@enomado
Copy link
Contributor

@enomado enomado commented Mar 2, 2026

Summary

When reordering a tab within the same node via drag-and-drop, DockState::move_tab calls remove_tab(src_tab) before insert_tab(index, tab). If the source and destination are the same node, this reduces the tab count by one — making the original destination index potentially out of bounds.

Example: A node has 3 tabs [A, B, C]. Dragging tab B (index 1) to position 3 (the end):

  1. remove_tab(1) → node becomes [A, C] (count = 2)
  2. insert_tab(3, B)panic, index 3 > count 2

Fix

Clamp the insertion index to the current tab count after removal. This is safe because inserting at count is equivalent to appending — which is the correct semantic for "move to the end".

Test plan

  • Drag a tab to the last position within its own node — no panic
  • Drag tabs between different nodes — unchanged behavior
  • Drag tabs to split positions — unchanged behavior

When reordering a tab within the same node, `remove_tab` is called
before `insert_tab`. This reduces the tab count by one, so the
original destination index may now be out of bounds.

Clamp the insertion index to the current tab count to prevent panic.
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.

1 participant