From b5ec511c38446c743ed190e7f91501d2dd831da4 Mon Sep 17 00:00:00 2001 From: Scott Sumner <30118311+sasumner@users.noreply.github.com> Date: Mon, 11 Jan 2021 07:48:43 -0500 Subject: [PATCH] Add ability to delete from Find combobox history When any of the Find window comboboxes are dropped and an entry is highlighted, pressing the Delete key will remove the highlighted entry from the following comboboxes: 1. Find what combobox 2. Replace with combobox 3. Directory combobox 4. Filters combobox No method is provided for clearing all entries at once, but as the "depth" of the comboboxes is limited to a small amount, clearing one entry at a time (when one wants to clear all) is not overly burdensome. Fix #9366, close #9396 --- .../src/ScitillaComponent/FindReplaceDlg.cpp | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index a4634e33d..2adbd7e68 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -443,10 +443,9 @@ int FindReplaceDlg::saveComboHistory(int id, int maxcount, vector(::SendMessage(hCombo, CB_GETCOUNT, 0, 0)); count = min(count, maxcount); - if (count == CB_ERR) return 0; + if (count == CB_ERR) return 0; - if (count) - strings.clear(); + strings.clear(); if (saveEmpty) { @@ -456,7 +455,7 @@ int FindReplaceDlg::saveComboHistory(int id, int maxcount, vector(comboEditProc)); + SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast(cbinfo.hwndCombo)); GetComboBoxInfo(hReplaceCombo, &cbinfo); SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast(comboEditProc)); + SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast(cbinfo.hwndCombo)); GetComboBoxInfo(hFiltersCombo, &cbinfo); SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast(comboEditProc)); + SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast(cbinfo.hwndCombo)); GetComboBoxInfo(hDirCombo, &cbinfo); SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast(comboEditProc)); + SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast(cbinfo.hwndCombo)); if ((NppParameters::getInstance()).getNppGUI()._monospacedFontFindDlg) { @@ -3245,7 +3248,31 @@ LRESULT FAR PASCAL FindReplaceDlg::finderProc(HWND hwnd, UINT message, WPARAM wP LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - if (message == WM_CHAR && wParam == 0x7F) // ASCII "DEL" (Ctrl+Backspace) + HWND hwndCombo = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + + bool isDropped = ::SendMessage(hwndCombo, CB_GETDROPPEDSTATE, 0, 0) != 0; + + if (isDropped && (message == WM_KEYDOWN) && (wParam == VK_DELETE)) + { + int curSel = static_cast(::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0)); + if (curSel != CB_ERR) + { + int itemsRemaining = static_cast(::SendMessage(hwndCombo, CB_DELETESTRING, curSel, 0)); + // if we close the dropdown and reopen it, it will be correctly-sized for remaining items + ::SendMessage(hwndCombo, CB_SHOWDROPDOWN, FALSE, 0); + if (itemsRemaining > 0) + { + if (itemsRemaining == curSel) + { + --curSel; + } + ::SendMessage(hwndCombo, CB_SETCURSEL, curSel, 0); + ::SendMessage(hwndCombo, CB_SHOWDROPDOWN, TRUE, 0); + } + return 0; + } + } + else if (message == WM_CHAR && wParam == 0x7F) // ASCII "DEL" (Ctrl+Backspace) { delLeftWordInEdit(hwnd); return 0;