Skip to content

Commit

Permalink
#5810: Fix objective components not being re-indexed after removing one
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 21, 2021
1 parent 4b5e78c commit a687a08
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugins/dm.objectives/ComponentsDialog.cpp
Expand Up @@ -502,6 +502,25 @@ void ComponentsDialog::_onDeleteComponent(wxCommandEvent& ev)

// Erase the actual component
_components.erase(idx);

// #5810: Re-index the remaining components (shift all higher ones by -1)
auto highestKey = _components.rbegin();

if (highestKey != _components.rend())
{
for (auto key = idx + 1; key <= highestKey->first; ++key)
{
// Attempt to move the component with the given key
auto node = _components.extract(key);

// If a component was unlinked from the map, move it downwards by one index
if (!node.empty())
{
node.key()--;
_components.insert(std::move(node));
}
}
}
}

// Refresh the list
Expand Down

0 comments on commit a687a08

Please sign in to comment.