From 3fa51efce7b830e37b1e61a9aa7353e0cc8d8857 Mon Sep 17 00:00:00 2001 From: Cerno_b Date: Wed, 27 Sep 2023 21:16:24 +0200 Subject: [PATCH] Store and restore just typed search text on arrow key press Fix #14174, close #14204 --- .../src/ScintillaComponent/FindReplaceDlg.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 1ff7722b8..f5377efd3 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -4170,6 +4170,8 @@ LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM bool isDropped = ::SendMessage(hwndCombo, CB_GETDROPPEDSTATE, 0, 0) != 0; + static wchar_t draftString[FINDREPLACE_MAXLENGTH]{}; + if (isDropped && (message == WM_KEYDOWN) && (wParam == VK_DELETE)) { auto curSel = ::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0); @@ -4195,6 +4197,30 @@ LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM delLeftWordInEdit(hwnd); return 0; } + else if (message == WM_SETFOCUS) + { + draftString[0] = '\0'; + } + else if ((message == WM_KEYDOWN) && (wParam == VK_DOWN) && (::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0) == CB_ERR)) + { + // down key on unselected combobox item -> store current edit text as draft + ::SendMessage(hwndCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, reinterpret_cast(draftString)); + } + else if ((message == WM_KEYDOWN) && (wParam == VK_UP) && (::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0) == CB_ERR)) + { + // up key on unselected combobox item -> no change but select current edit text + ::SendMessage(hwndCombo, CB_SETEDITSEL, 0, MAKELPARAM(0, -1)); + return 0; + } + else if ((message == WM_KEYDOWN) && (wParam == VK_UP) && (::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0) == 0) && std::wcslen(draftString) > 0) + { + // up key on top selected combobox item -> restore draft to edit text + ::SendMessage(hwndCombo, CB_SETCURSEL, WPARAM(-1), 0); + ::SendMessage(hwndCombo, WM_SETTEXT, FINDREPLACE_MAXLENGTH - 1, reinterpret_cast(draftString)); + ::SendMessage(hwndCombo, CB_SETEDITSEL, 0, MAKELPARAM(0, -1)); + return 0; + + } return CallWindowProc(originalComboEditProc, hwnd, message, wParam, lParam); }