diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index 90b30a2..6aa16e9 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -140,6 +140,7 @@ int ME_SetSelection(ME_TextEditor *editor, int from, int to) ME_SetCursorToStart(editor, &editor->pCursors[1]); ME_SetCursorToEnd(editor, &editor->pCursors[0]); ME_InvalidateSelection(editor); + editor->pCursors[0].nOffset = editor->pCursors[0].pRun->member.run.len; return len + 1; } @@ -159,6 +160,11 @@ int ME_SetSelection(ME_TextEditor *editor, int from, int to) ME_GetSelectionOfs(editor, &start, &end); if (start != end) { + if (end > len) + { + editor->pCursors[0].nOffset = 0; + end --; + } editor->pCursors[1] = editor->pCursors[0]; ME_Repaint(editor); } @@ -199,7 +205,9 @@ int ME_SetSelection(ME_TextEditor *editor, int from, int to) /* Selection is not allowed in the middle of an end paragraph run. */ if (editor->pCursors[1].pRun->member.run.nFlags & MERF_ENDPARA) editor->pCursors[1].nOffset = 0; - if (editor->pCursors[0].pRun->member.run.nFlags & MERF_ENDPARA) + if (editor->pCursors[0].pRun->member.run.nFlags & MERF_ENDPARA && to > len) + editor->pCursors[0].nOffset = editor->pCursors[0].pRun->member.run.len; + else if (editor->pCursors[0].pRun->member.run.nFlags & MERF_ENDPARA) editor->pCursors[0].nOffset = 0; return to; } diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 3bd3ec0..879aa6a 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -4363,7 +4363,7 @@ const struct exsetsel_s exsetsel_tests[] = { {5, 10, 10, 5, 10, 0}, {15, 17, 17, 15, 17, 0}, /* test cpMax > strlen() */ - {0, 100, 18, 0, 18, 1}, + {0, 100, 18, 0, 18, 0}, /* test cpMin == cpMax */ {5, 5, 5, 5, 5, 0}, /* test cpMin < 0 && cpMax >= 0 (bug 4462) */ @@ -4374,12 +4374,14 @@ const struct exsetsel_s exsetsel_tests[] = { {-1, -1, 17, 17, 17, 0}, {-4, -5, 17, 17, 17, 0}, /* test cMin >=0 && cpMax < 0 (bug 6814) */ - {0, -1, 18, 0, 18, 1}, - {17, -5, 18, 17, 18, 1}, + {0, -1, 18, 0, 18, 0}, + {17, -5, 18, 17, 18, 0}, {18, -3, 17, 17, 17, 0}, /* test if cpMin > cpMax */ - {15, 19, 18, 15, 18, 1}, - {19, 15, 18, 15, 18, 1} + {15, 19, 18, 15, 18, 0}, + {19, 15, 18, 15, 18, 0}, + {0, -1, 18, 0, 18, 0}, + {-1, 1, 17, 17, 17, 0} }; static void check_EM_EXSETSEL(HWND hwnd, const struct exsetsel_s *setsel, int id) {