Skip to content

Commit

Permalink
Remember last-used string in the Find dialog in conhost (#2845)
Browse files Browse the repository at this point in the history
(cherry picked from commit bfb1484)
  • Loading branch information
asklar authored and DHowett committed Sep 26, 2019
1 parent 93bc0af commit 4bcb283
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/interactivity/win32/find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ 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)
{
case WM_INITDIALOG:
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:
{
Expand All @@ -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;
Expand All @@ -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(); });

Expand Down

0 comments on commit 4bcb283

Please sign in to comment.