diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index fcfe03acf6c..81fe9b2ba40 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -1908,8 +1908,18 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */ if (lstrlenW(wszText) > 0) { + int len = -1; + /* uses default style! */ - ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle); + if (!(GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE)) + { + WCHAR * p; + + p = wszText; + while (*p != '\0' && *p != '\r' && *p != '\n') p++; + len = p - wszText; + } + ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle); } ME_EndToUnicode(unicode, wszText); } diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index de36d6ead65..5375d305868 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -2064,6 +2064,9 @@ static void test_EM_GETTEXTLENGTHEX(void) HWND hwnd; GETTEXTLENGTHEX gtl; int ret; + const char * test_string = "a\nb\n\n\r\n"; + const char * test_string_after = "a"; + char buffer[64] = {0}; /* single line */ hwnd = CreateWindowExA(0, "RichEdit20W", NULL, WS_POPUP, @@ -2080,17 +2083,21 @@ static void test_EM_GETTEXTLENGTHEX(void) ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); ok(ret == 0, "ret %d\n",ret); - SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) "a\nb\n\n\r\n"); + SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) test_string); gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF; gtl.codepage = CP_ACP; ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); - todo_wine ok(ret == 1, "ret %d\n",ret); + ok(ret == 1, "ret %d\n",ret); gtl.flags = GTL_NUMCHARS | GTL_PRECISE; gtl.codepage = CP_ACP; ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); - todo_wine ok(ret == 1, "ret %d\n",ret); + ok(ret == 1, "ret %d\n",ret); + + SendMessage(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer); + ret = strcmp(buffer, test_string_after); + ok(ret == 0, "WM_GETTEXT recovered incorrect string!\n"); DestroyWindow(hwnd); @@ -2109,7 +2116,7 @@ static void test_EM_GETTEXTLENGTHEX(void) ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0); ok(ret == 0, "ret %d\n",ret); - SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) "a\nb\n\n\r\n"); + SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) test_string); gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF; gtl.codepage = CP_ACP;