Huw Davies : riched20: Correctly handle the cursor at the end of a run case.

Alexandre Julliard julliard at winehq.org
Tue Jan 7 13:21:18 CST 2014


Module: wine
Branch: master
Commit: 86ea91f4243fcef2370cfc523a86c59bc9d202b9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=86ea91f4243fcef2370cfc523a86c59bc9d202b9

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Jan  7 12:44:22 2014 +0000

riched20: Correctly handle the cursor at the end of a run case.

---

 dlls/riched20/run.c |   47 ++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 9 deletions(-)

diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c
index 176f7c9..204431e 100644
--- a/dlls/riched20/run.c
+++ b/dlls/riched20/run.c
@@ -310,23 +310,52 @@ ME_DisplayItem *
 ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
                      const WCHAR *str, int len, int flags)
 {
-  ME_DisplayItem *pDI;
+  ME_DisplayItem *pDI, *insert_before = cursor->pRun, *prev;
 
   if (cursor->nOffset)
-    ME_SplitRunSimple(editor, cursor);
+  {
+    if (cursor->nOffset == cursor->pRun->member.run.len)
+    {
+      insert_before = ME_FindItemFwd( cursor->pRun, diRun );
+      if (!insert_before) insert_before = cursor->pRun; /* Always insert before the final eop run */
+    }
+    else
+    {
+      ME_SplitRunSimple( editor, cursor );
+      insert_before = cursor->pRun;
+    }
+  }
 
-  add_undo_delete_run( editor, cursor->pPara->member.para.nCharOfs +
-                       cursor->pRun->member.run.nCharOfs, len );
+  add_undo_delete_run( editor, insert_before->member.run.para->nCharOfs +
+                       insert_before->member.run.nCharOfs, len );
 
   pDI = ME_MakeRun(style, flags);
-  pDI->member.run.nCharOfs = cursor->pRun->member.run.nCharOfs;
+  pDI->member.run.nCharOfs = insert_before->member.run.nCharOfs;
   pDI->member.run.len = len;
-  pDI->member.run.para = cursor->pRun->member.run.para;
+  pDI->member.run.para = insert_before->member.run.para;
   ME_InsertString( pDI->member.run.para->text, pDI->member.run.nCharOfs, str, len );
-  ME_InsertBefore(cursor->pRun, pDI);
+  ME_InsertBefore( insert_before, pDI );
   TRACE("Shift length:%d\n", len);
-  ME_PropagateCharOffset(cursor->pRun, len);
-  cursor->pPara->member.para.nFlags |= MEPF_REWRAP;
+  ME_PropagateCharOffset( insert_before, len );
+  insert_before->member.run.para->nFlags |= MEPF_REWRAP;
+
+  /* Move any cursors that were at the end of the previous run to the end of the inserted run */
+  prev = ME_FindItemBack( pDI, diRun );
+  if (prev)
+  {
+    int i;
+
+    for (i = 0; i < editor->nCursors; i++)
+    {
+      if (editor->pCursors[i].pRun == prev &&
+          editor->pCursors[i].nOffset == prev->member.run.len)
+      {
+        editor->pCursors[i].pRun = pDI;
+        editor->pCursors[i].nOffset = len;
+      }
+    }
+  }
+
   return pDI;
 }
 




More information about the wine-cvs mailing list