From 4bcb283274693dab6e089ac99e7002e96250fab3 Mon Sep 17 00:00:00 2001 From: Alexander Sklar Date: Mon, 23 Sep 2019 07:16:40 -0700 Subject: [PATCH] Remember last-used string in the Find dialog in conhost (#2845) (cherry picked from commit bfb14847082f9ae085efe1c6b8cba16027815bca) --- src/interactivity/win32/find.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interactivity/win32/find.cpp b/src/interactivity/win32/find.cpp index 91124cec480..db995dc3683 100644 --- a/src/interactivity/win32/find.cpp +++ b/src/interactivity/win32/find.cpp @@ -23,6 +23,8 @@ INT_PTR CALLBACK FindDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM l // This bool is used to track which option - up or down - was used to perform the last search. That way, the next time the // find dialog is opened, it will default to the last used option. static bool fFindSearchUp = true; + static std::wstring lastFindString; + WCHAR szBuf[SEARCH_STRING_LENGTH + 1]; switch (Message) { @@ -30,6 +32,7 @@ INT_PTR CALLBACK FindDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM l SetWindowLongPtrW(hWnd, DWLP_USER, lParam); SendDlgItemMessageW(hWnd, ID_CONSOLE_FINDSTR, EM_LIMITTEXT, ARRAYSIZE(szBuf) - 1, 0); CheckRadioButton(hWnd, ID_CONSOLE_FINDUP, ID_CONSOLE_FINDDOWN, (fFindSearchUp ? ID_CONSOLE_FINDUP : ID_CONSOLE_FINDDOWN)); + SetDlgItemText(hWnd, ID_CONSOLE_FINDSTR, lastFindString.c_str()); return TRUE; case WM_COMMAND: { @@ -40,6 +43,7 @@ INT_PTR CALLBACK FindDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM l USHORT const StringLength = (USHORT)GetDlgItemTextW(hWnd, ID_CONSOLE_FINDSTR, szBuf, ARRAYSIZE(szBuf)); if (StringLength == 0) { + lastFindString.clear(); break; } bool const IgnoreCase = IsDlgButtonChecked(hWnd, ID_CONSOLE_FINDCASE) == 0; @@ -48,7 +52,7 @@ INT_PTR CALLBACK FindDialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM l SCREEN_INFORMATION& ScreenInfo = gci.GetActiveOutputBuffer(); std::wstring wstr(szBuf, StringLength); - + lastFindString = wstr; LockConsole(); auto Unlock = wil::scope_exit([&] { UnlockConsole(); });