From 30976ec8d23bea169b32b1205298c209db0b7cf7 Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Wed, 30 Apr 2025 15:33:55 -0700 Subject: [PATCH] Fix ShortcutMapper displays wrong shortcut while editing regression (from v8.7.6) Fix double clicking chosen command in ShortcutMapper displays wrong shortcut due to the bad index. - 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. The regression was introduced by: https://github.com/notepad-plus-plus/notepad-plus-plus/commit/6dfbc1f7e8d5bc770786a5e38c1be71a7f1c0b0d Fix #16491, close #16492 --- PowerEditor/src/WinControls/shortcut/shortcut.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index b4456baad..cafd5857c 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -553,6 +553,7 @@ intptr_t CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar // while buiding the IDC_KEY_COMBO keys, update the map to which VirtualKey is used for each index int iFound = -1; + oemVkUsedIDs.clear(); // the logic below (always pushing onto the vector) requires that it starts fresh every time, otherwise it will grow every time the dialog is launched for (size_t i = 0 ; i < nbKeys ; ++i) { const char* nameStr = namedKeyArray[i].name; @@ -571,7 +572,7 @@ intptr_t CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar } if (_keyCombo._key == namedKeyArray[i].id) - iFound = static_cast(oemVkUsedIDs.size()); + iFound = static_cast(oemVkUsedIDs.size())-1; // -1 because it's already been added, so the most recent index of oemVkUsedIDs is 1 less than the length } if (iFound != -1) @@ -1243,6 +1244,7 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR ::SetDlgItemText(_hSelf, IDC_NAME_EDIT, string2wstring(_name, CP_UTF8).c_str()); _keyCombo = _keyCombos[0]; + oemVkUsedIDs.clear(); // the logic below (always pushing onto the vector) requires that it starts fresh every time, otherwise it will grow every time the dialog is launched for (size_t i = 0 ; i < nbKeys ; ++i) {