[PATCH 1/2] riched20: Implement ITextSelection::GetText. (try 3)

Jactry Zeng jactry92 at gmail.com
Fri Jul 18 12:08:19 CDT 2014


Hi Huw,

Is this the right way?
Testbot result: https://testbot.winehq.org/JobDetails.pl?Key=8030


2014-07-16 19:44 GMT+08:00 Huw Davies <huw at codeweavers.com>:

> On 15 Jul 2014, at 14:43, Jactry Zeng wrote:
> 2014-07-15 21:29 GMT+08:00 Huw Davies <huw at codeweavers.com>:
> > >
> > > Can you at least point to a test that shows this bug?
> >
> > Do you mean tests about bug of S/GetSelection?
> > It seem is a known bug:
> >
> http://source.winehq.org/git/wine.git/blob/HEAD:/dlls/riched20/tests/editor.c#l4366
>
> Yes.  So adding a special case to SetSelection should fix this.
>
> 'to' is already setup correctly to len+1, so the problem is
> adjusting cursors[0].  MoveCursorChars is clamping the
> cursor to len.
>
> So you have two options, either alter MoveCursorChars
> to allow it to move to len + 1. You'd need to retain the current
> behaviour in some circumstances though (such as moving
> to the right on right-arrow keys press), so you'd need to pass
> a flag or something.
>
> Option 2 is just the modify cursor[0] in SetSelection.  If this
> is the only place where one can select the final EOP, then
> this is probably the preferred solution.
>
> Either way, you probably need to change the 'middle of
> end paragraph run' fix up for cursor[0] at the end of
> SetSelection (probably by setting nOffset = run.len).
>
> Having done this, check the tests still work (and the
> todos are fixed). Also play with wordpad for a while
> to see it behaves correctly.
>
> Does that make sense?
>
> Huw.
>
>
>


-- 
Regards,
Jactry Zeng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20140719/d7c49fc8/attachment.html>
-------------- next part --------------
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) {


More information about the wine-devel mailing list