[PATCH v2 0/2] MR10888: riched20: Implement EM_LINELENGTH with wParam==-1
MS Comic Chat requires EM_LINELENGTH with wParam==-1 to be implemented in riched20 to allow typing space characters. EM_LINELENGTH(-1) returns the number of unselected characters on the line that contains the current selection. -- v2: riched20/tests: Add EM_LINELENGTH(-1) tests riched20: Implement EM_LINELENGTH with wParam==-1 https://gitlab.winehq.org/wine/wine/-/merge_requests/10888
From: Rose Hellsing <rose@pinkro.se> MS Comic Chat requires EM_LINELENGTH with wParam==-1 to be implemented in riched20 to allow typing space characters. EM_LINELENGTH(-1) returns the number of unselected characters on the line that contains the current selection. --- dlls/riched20/editor.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 1a0c444579b..e704508f2a5 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -3806,13 +3806,31 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam, int start_ofs, end_ofs; ME_Cursor cursor; - if (wParam > ME_GetTextLength(editor)) - return 0; if (wParam == -1) { - FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n"); - return 0; + LONG from, to; + int line_start, line_end, line_len, result; + + ME_GetSelectionOfs( editor, &from, &to ); + + cursor_from_char_ofs( editor, from, &cursor ); + row = row_from_cursor( &cursor ); + row_first_cursor( row, &cursor ); + line_start = ME_GetCursorOfs( &cursor ); + + cursor_from_char_ofs( editor, to, &cursor ); + row = row_from_cursor( &cursor ); + row_first_cursor( row, &cursor ); + line_end = ME_GetCursorOfs( &cursor ); + row_end_cursor( row, &cursor, FALSE ); + line_len = ME_GetCursorOfs( &cursor ) - line_end; + + result = (from - line_start) + (line_end + line_len - to); + TRACE( "EM_LINELENGTH(-1): sel=%ld..%ld result=%d\n", from, to, result ); + return result; } + if (wParam > ME_GetTextLength(editor)) + return 0; cursor_from_char_ofs( editor, wParam, &cursor ); row = row_from_cursor( &cursor ); row_first_cursor( row, &cursor ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10888
From: Rose Hellsing <rose@pinkro.se> --- dlls/riched20/tests/editor.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 19cd40aea48..0a7b8ec6ce4 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -535,6 +535,31 @@ static void test_EM_LINELENGTH(void) offset_test[i][0], result, offset_test[i][1]); } + /* EM_LINELENGTH with wParam == -1 returns the count of unselected + * characters on the line(s) containing the selection. */ + SendMessageA(hwndRichEdit, EM_SETSEL, 0, 0); + result = SendMessageA(hwndRichEdit, EM_LINELENGTH, -1, 0); + ok(result == 9, "EM_LINELENGTH(-1) with caret at start: got %Id, expected 9\n", result); + + SendMessageA(hwndRichEdit, EM_SETSEL, 5, 5); + result = SendMessageA(hwndRichEdit, EM_LINELENGTH, -1, 0); + ok(result == 9, "EM_LINELENGTH(-1) with caret mid-line: got %Id, expected 9\n", result); + + /* Selection entirely within one line: unselected chars on that line */ + SendMessageA(hwndRichEdit, EM_SETSEL, 2, 5); + result = SendMessageA(hwndRichEdit, EM_LINELENGTH, -1, 0); + ok(result == 6, "EM_LINELENGTH(-1) with sel 2..5 on line 1: got %Id, expected 6\n", result); + + /* Selection spanning two lines: unselected chars on first + last line */ + SendMessageA(hwndRichEdit, EM_SETSEL, 4, 13); + result = SendMessageA(hwndRichEdit, EM_LINELENGTH, -1, 0); + ok(result == 10, "EM_LINELENGTH(-1) with sel 4..13: got %Id, expected 10\n", result); + + /* Caret at end of text */ + SendMessageA(hwndRichEdit, EM_SETSEL, 39, 39); + result = SendMessageA(hwndRichEdit, EM_LINELENGTH, -1, 0); + ok(result == 9, "EM_LINELENGTH(-1) with caret at end: got %Id, expected 9\n", result); + /* Test with multibyte character */ if (!is_lang_japanese) skip("Skip multibyte character tests on non-Japanese platform\n"); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10888
On Thu May 14 11:50:17 2026 +0000, Huw Davies wrote:
Could we have a test for this please? There are already `EM_LINELENGTH` tests in `test_EM_LINELENGTH()`. Expanded `test_EM_LINELENGTH()` with some basic cases for `wParam=-1`, hope these are okay!
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10888#note_139811
This merge request was approved by Huw Davies. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10888
participants (3)
-
Huw Davies (@huw) -
Rose Hellsing -
Rose Hellsing (@axtlos)