https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e1a01de7f7cbd6529b70bfc00c61b4df1fab82a8

commit e1a01de7f7cbd6529b70bfc00c61b4df1fab82a8
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Mon Sep 28 22:05:14 2020 +0900
Commit:     GitHub <[email protected]>
CommitDate: Mon Sep 28 22:05:14 2020 +0900

    [BROWSEUI] Fix Edit_BackWord function (#3247)
    
    Fix and improve Edit_BackWord function (for Ctrl+Back key combination on 
auto-completion in edit boxes) by using GetStringTypeW. CORE-1419
---
 dll/win32/browseui/CAutoComplete.cpp | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/dll/win32/browseui/CAutoComplete.cpp 
b/dll/win32/browseui/CAutoComplete.cpp
index 008a8185baa..b18956b6547 100644
--- a/dll/win32/browseui/CAutoComplete.cpp
+++ b/dll/win32/browseui/CAutoComplete.cpp
@@ -287,32 +287,30 @@ static void Edit_BackWord(HWND hwndEdit)
     iStart = iEnd = 0;
     SendMessageW(hwndEdit, EM_GETSEL, (WPARAM)&iStart, (LPARAM)&iEnd);
 
-    if (iStart != iEnd)
+    if (iStart != iEnd || iStart < 0)
         return;
 
-    DWORD cchText = GetWindowTextLengthW(hwndEdit);
-    size_t cb = (cchText + 1) * sizeof(WCHAR);
-    LPWSTR pszText = (LPWSTR)CoTaskMemAlloc(cb);
-    if (pszText == NULL)
+    size_t cchText = GetWindowTextLengthW(hwndEdit);
+    if (cchText < (size_t)iStart || (INT)cchText <= 0)
+        return;
+
+    CComHeapPtr<WCHAR> pszText;
+    if (!pszText.Allocate(cchText + 1))
         return;
 
     if (GetWindowTextW(hwndEdit, pszText, cchText + 1) <= 0)
-    {
-        CoTaskMemFree(pszText);
         return;
-    }
 
-    for (; 0 < iStart; --iStart)
+    WORD types[2];
+    for (--iStart; 0 < iStart; --iStart)
     {
-        WCHAR ch1 = pszText[iStart - 1];
-        WCHAR ch2 = pszText[iStart];
-        if ((wcschr(L"\\/.:;", ch1) && ch2 && !IsCharSpaceW(ch2)) ||
-            (IsCharSpaceW(ch1) && IsCharAlphaNumericW(ch2)))
+        GetStringTypeW(CT_CTYPE1, &pszText[iStart - 1], 2, types);
+        if (((types[0] & C1_PUNCT) && !(types[1] & C1_SPACE)) ||
+            ((types[0] & C1_SPACE) && (types[1] & (C1_ALPHA | C1_DIGIT))))
         {
             SendMessageW(hwndEdit, EM_SETSEL, iStart, iEnd);
             SendMessageW(hwndEdit, EM_REPLACESEL, TRUE, (LPARAM)L"");
-            iStart = -1;
-            break;
+            return;
         }
     }
 
@@ -321,8 +319,6 @@ static void Edit_BackWord(HWND hwndEdit)
         SendMessageW(hwndEdit, EM_SETSEL, iStart, iEnd);
         SendMessageW(hwndEdit, EM_REPLACESEL, TRUE, (LPARAM)L"");
     }
-
-    CoTaskMemFree(pszText);
 }
 
 /*

Reply via email to