Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember last-used string in the Find dialog in conhost #2845

Merged
merged 1 commit into from
Sep 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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