[BROWSEUI][SHELL32] Enable Ctrl+Backspace in AutoComplete edit boxes (#3242)

The key combination Ctrl+Back is well working in auto-completion edit boxes. CORE-1419
This commit is contained in:
Katayama Hirofumi MZ 2020-09-28 09:27:01 +09:00 committed by GitHub
parent f5ba9de2ee
commit 6b6f971939
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View file

@ -3,6 +3,7 @@
*
* Copyright 2004 Maxime Bellengé <maxime.bellenge@laposte.net>
* Copyright 2009 Andrew Hill
* Copyright 2020 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -279,6 +280,48 @@ HRESULT WINAPI CAutoComplete::SetOptions(DWORD dwFlag)
return hr;
}
/* Edit_BackWord --- Delete previous word in text box */
static void Edit_BackWord(HWND hwndEdit)
{
INT iStart, iEnd;
iStart = iEnd = 0;
SendMessageW(hwndEdit, EM_GETSEL, (WPARAM)&iStart, (LPARAM)&iEnd);
if (iStart != iEnd)
return;
DWORD cchText = GetWindowTextLengthW(hwndEdit);
size_t cb = (cchText + 1) * sizeof(WCHAR);
LPWSTR pszText = (LPWSTR)CoTaskMemAlloc(cb);
if (pszText == NULL)
return;
if (GetWindowTextW(hwndEdit, pszText, cchText + 1) <= 0)
{
CoTaskMemFree(pszText);
return;
}
for (; 0 < iStart; --iStart)
{
if (IsCharSpaceW(pszText[iStart - 1]) && IsCharAlphaNumericW(pszText[iStart]))
{
SendMessageW(hwndEdit, EM_SETSEL, iStart, iEnd);
SendMessageW(hwndEdit, EM_REPLACESEL, TRUE, (LPARAM)L"");
iStart = -1;
break;
}
}
if (iStart == 0)
{
SendMessageW(hwndEdit, EM_SETSEL, iStart, iEnd);
SendMessageW(hwndEdit, EM_REPLACESEL, TRUE, (LPARAM)L"");
}
CoTaskMemFree(pszText);
}
/*
Window procedure for autocompletion
*/
@ -407,6 +450,14 @@ LRESULT APIENTRY CAutoComplete::ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM
}; break;
case VK_BACK:
{
if (GetKeyState(VK_CONTROL) < 0) // Ctrl+Backspace
{
Edit_BackWord(hwnd);
return 0;
}
}
// FALL THROUGH
case VK_DELETE:
{
if ((! *hwndText) && (pThis->options & ACO_AUTOSUGGEST))

View file

@ -547,11 +547,18 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARA
ComboInfo.cbSize = sizeof(ComboInfo);
GetComboBoxInfo(hwndCombo, &ComboInfo);
hwndEdit = ComboInfo.hwndItem;
ASSERT(::IsWindow(hwndEdit));
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); // SHAutoComplete needs co init
SHAutoComplete(hwndEdit, SHACF_FILESYSTEM | SHACF_FILESYS_ONLY | SHACF_URLALL);
SetFocus(hwndCombo);
return TRUE;
case WM_DESTROY:
CoUninitialize();
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{