ShortcutMapper: fix active shortcut index#16492
ShortcutMapper: fix active shortcut index#16492pryrt wants to merge 2 commits intonotepad-plus-plus:masterfrom
Conversation
- there was off-by-1 when building the oemVkUsedIDs vector, which was caused by using the index based on .size() instead of .size()-1 to get the most-recently-added - also cleared the vector each launch of the dialog, because the .push_back() was causing the vector to grow without bounds, messing up the indexing on subsequent runs of the dialog, causing it to pick _none_ of the entries
|
Tested - ok. @pryrt |
Thanks.
I was really hoping that v8.8 would be the next auto-update. Sorry for this bug. |
|
|
||
| if (_keyCombo._key == namedKeyArray[i].id) | ||
| iFound = static_cast<int32_t>(oemVkUsedIDs.size()); | ||
| iFound = static_cast<int32_t>(oemVkUsedIDs.size()-1); // -1 because it's already been added, so the most recent index of oemVkUsedIDs is 1 less than the length |
There was a problem hiding this comment.
iFound = static_cast<int32_t>(oemVkUsedIDs.size() - 1); should be iFound = static_cast<int32_t>(oemVkUsedIDs.size()) - 1; to convert size_t to int32_t before, then do the substraction.
|
|
||
| if (_keyCombo._key == namedKeyArray[i].id) | ||
| iFound = static_cast<int32_t>(oemVkUsedIDs.size()-1); // -1 because it's already been added, so the most recent index of oemVkUsedIDs is 1 less than the length | ||
| iFound = static_cast<int32_t>(oemVkUsedIDs.size())-1; // -1 because it's already been added, so the most recent index of oemVkUsedIDs is 1 less than the length |
There was a problem hiding this comment.
It's always better to keep the code readability: Write static_cast<int32_t>(oemVkUsedIDs.size()) - 1 instead of static_cast<int32_t>(oemVkUsedIDs.size())-1. But it's OK for this time.
|
The regression was introduced by: 6dfbc1f |
there was off-by-1 when building the oemVkUsedIDs vector, which was caused by using the index based on .size() instead of .size()-1 to get the most-recently-added
also cleared the vector each launch of the dialog, because the .push_back() was causing the vector to grow without bounds, messing up the indexing on subsequent runs of the dialog, causing it to pick none of the entries
fixes #16491