fix: clamp tab index in move_tab to prevent out-of-bounds insert#308
Merged
anhosh merged 2 commits intoanhosh:release-0.19from Mar 22, 2026
Merged
Conversation
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.
anhosh
approved these changes
Mar 22, 2026
Owner
anhosh
left a comment
There was a problem hiding this comment.
Thanks for spotting and fixing this!
Merged
anhosh
added a commit
that referenced
this pull request
Mar 29, 2026
* impl Index<TabIndex> for LeafNode (#311) * fix(layout): prevent panics on extreme window shrink (#307) (#309) * fix: clamp tab index in move_tab to prevent out-of-bounds insert (#308) * fix: clamp tab index in move_tab to prevent out-of-bounds insert 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. * Simplify the clamping --------- Co-authored-by: Adanos020 <adanos020@gmail.com> * Refactor index tuples to structs (#312) * Refactor index tuples to structs * add convenience functions on NodePath and TabPat * reorganize imports * refactor some fallible methods to return an Error --------- Co-authored-by: Adam Gąsior <adanos020@gmail.com> * Update egui/eframe to 0.34 (#314) * Update egui/eframe to 0.34 - Bump egui from 0.33 to 0.34 - Bump eframe from 0.33 to 0.34 - Deprecate DockArea::show(ctx) in favor of show_inside(ui) - Migrate all examples to eframe's new App::ui(&mut Ui) API - Replace deprecated ctx.style() with ctx.global_style() - Fix deprecated warnings in doc-tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: cargo fmt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update changelog * Update Cargo.toml and README.md * Fix clippy warnings --------- Co-authored-by: Jonathan Chan Kwan Yin <sofe2038@gmail.com> Co-authored-by: Matias Lopez <109480516+MatiasLopezING@users.noreply.github.com> Co-authored-by: Ivan <ixentrum@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When reordering a tab within the same node via drag-and-drop,
DockState::move_tabcallsremove_tab(src_tab)beforeinsert_tab(index, tab). If the source and destination are the same node, this reduces the tab count by one — making the original destinationindexpotentially out of bounds.Example: A node has 3 tabs
[A, B, C]. Dragging tabB(index 1) to position 3 (the end):remove_tab(1)→ node becomes[A, C](count = 2)insert_tab(3, B)→ panic, index 3 > count 2Fix
Clamp the insertion index to the current tab count after removal. This is safe because inserting at
countis equivalent to appending — which is the correct semantic for "move to the end".Test plan