Huw Davies : riched20: Allow selecting the final end-of-paragraph when using the right arrow key.

Alexandre Julliard julliard at winehq.org
Tue Oct 4 13:38:25 CDT 2016


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

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Oct  4 13:07:33 2016 +0100

riched20: Allow selecting the final end-of-paragraph when using the right arrow key.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/riched20/caret.c   | 15 ++++++++-------
 dlls/riched20/editor.c  |  6 +++---
 dlls/riched20/editor.h  |  2 +-
 dlls/riched20/richole.c |  2 +-
 dlls/riched20/table.c   |  2 +-
 dlls/riched20/undo.c    |  2 +-
 dlls/riched20/writer.c  |  5 +----
 7 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 279bdcd..b137c5f 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -200,7 +200,7 @@ int ME_SetSelection(ME_TextEditor *editor, int from, int to)
 
   ME_CursorFromCharOfs(editor, from, &editor->pCursors[1]);
   editor->pCursors[0] = editor->pCursors[1];
-  ME_MoveCursorChars(editor, &editor->pCursors[0], to - from);
+  ME_MoveCursorChars(editor, &editor->pCursors[0], to - from, FALSE);
   /* 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;
@@ -627,10 +627,11 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
 }
 
 /* Move the cursor nRelOfs characters (either forwards or backwards)
+ * If final_eop is TRUE, allow moving the cursor to the end of the final eop.
  *
  * returns the actual number of characters moved.
  **/
-int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
+int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BOOL final_eop)
 {
   cursor->nOffset += nRelOfs;
   if (cursor->nOffset < 0)
@@ -682,11 +683,11 @@ int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
       return nRelOfs;
     }
 
-    if (new_offset >= ME_GetTextLength(editor))
+    if (new_offset >= ME_GetTextLength(editor) + (final_eop ? 1 : 0))
     {
       /* new offset at the end of the text */
-      ME_SetCursorToEnd(editor, cursor, FALSE);
-      nRelOfs -= new_offset - ME_GetTextLength(editor);
+      ME_SetCursorToEnd(editor, cursor, final_eop);
+      nRelOfs -= new_offset - (ME_GetTextLength(editor) + (final_eop ? 1 : 0));
       return nRelOfs;
     }
 
@@ -1547,14 +1548,14 @@ ME_ArrowKey(ME_TextEditor *editor, int nVKey, BOOL extend, BOOL ctrl)
       if (ctrl)
         success = ME_MoveCursorWords(editor, &tmp_curs, -1);
       else
-        success = ME_MoveCursorChars(editor, &tmp_curs, -1);
+        success = ME_MoveCursorChars(editor, &tmp_curs, -1, extend);
       break;
     case VK_RIGHT:
       editor->bCaretAtEnd = FALSE;
       if (ctrl)
         success = ME_MoveCursorWords(editor, &tmp_curs, +1);
       else
-        success = ME_MoveCursorChars(editor, &tmp_curs, +1);
+        success = ME_MoveCursorChars(editor, &tmp_curs, +1, extend);
       break;
     case VK_UP:
       ME_MoveCursorLines(editor, &tmp_curs, -1);
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 97c2d59..4adc74f 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1650,7 +1650,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
           int linebreakSize = editor->bEmulateVersion10 ? 2 : 1;
           ME_Cursor linebreakCursor = *selEnd;
 
-          ME_MoveCursorChars(editor, &linebreakCursor, -linebreakSize);
+          ME_MoveCursorChars(editor, &linebreakCursor, -linebreakSize, FALSE);
           ME_GetTextW(editor, lastchar, 2, &linebreakCursor, linebreakSize, FALSE, FALSE);
           if (lastchar[0] == '\r' && (lastchar[1] == '\n' || lastchar[1] == '\0')) {
             ME_InternalDeleteText(editor, &linebreakCursor, linebreakSize, FALSE);
@@ -1805,7 +1805,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
     {
       ME_CursorFromCharOfs(editor, nMin - 1, &cursor);
       wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
-      ME_MoveCursorChars(editor, &cursor, 1);
+      ME_MoveCursorChars(editor, &cursor, 1, FALSE);
     } else {
       ME_CursorFromCharOfs(editor, nMin, &cursor);
     }
@@ -1881,7 +1881,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
     {
       ME_CursorFromCharOfs(editor, nMax + 1, &cursor);
       wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
-      ME_MoveCursorChars(editor, &cursor, -1);
+      ME_MoveCursorChars(editor, &cursor, -1, FALSE);
     } else {
       ME_CursorFromCharOfs(editor, nMax, &cursor);
     }
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index cc1654a..c62b3a4 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -178,7 +178,7 @@ BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars) DECLS
 void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, 
                              const WCHAR *str, int len, ME_Style *style) DECLSPEC_HIDDEN;
 void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor) DECLSPEC_HIDDEN;
-int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) DECLSPEC_HIDDEN;
+int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BOOL final_eop) DECLSPEC_HIDDEN;
 BOOL ME_ArrowKey(ME_TextEditor *ed, int nVKey, BOOL extend, BOOL ctrl) DECLSPEC_HIDDEN;
 
 int ME_GetCursorOfs(const ME_Cursor *cursor) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 77e7b57..c5f0441 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -451,7 +451,7 @@ static HRESULT get_textfont_prop_for_pos(const IRichEditOleImpl *reole, int pos,
 
     ME_CursorFromCharOfs(reole->editor, pos, &from);
     to = from;
-    ME_MoveCursorChars(reole->editor, &to, 1);
+    ME_MoveCursorChars(reole->editor, &to, 1, FALSE);
     ME_GetCharFormat(reole->editor, &from, &to, &fmt);
 
     switch (propid)
diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c
index c22f92a..b834bc7 100644
--- a/dlls/riched20/table.c
+++ b/dlls/riched20/table.c
@@ -291,7 +291,7 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nC
   ME_DisplayItem *this_para = c->pPara;
   ME_DisplayItem *end_para;
 
-  ME_MoveCursorChars(editor, &c2, *nChars);
+  ME_MoveCursorChars(editor, &c2, *nChars, FALSE);
   end_para = c2.pPara;
   if (c2.pRun->member.run.nFlags & MERF_ENDPARA) {
     /* End offset might be in the middle of the end paragraph run.
diff --git a/dlls/riched20/undo.c b/dlls/riched20/undo.c
index 7a8c333..582f888 100644
--- a/dlls/riched20/undo.c
+++ b/dlls/riched20/undo.c
@@ -349,7 +349,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
     ME_Cursor start, end;
     ME_CursorFromCharOfs(editor, undo->u.set_char_fmt.pos, &start);
     end = start;
-    ME_MoveCursorChars(editor, &end, undo->u.set_char_fmt.len);
+    ME_MoveCursorChars(editor, &end, undo->u.set_char_fmt.len, FALSE);
     ME_SetCharFormat(editor, &start, &end, &undo->u.set_char_fmt.fmt);
     break;
   }
diff --git a/dlls/riched20/writer.c b/dlls/riched20/writer.c
index a3eaffe..0204215 100644
--- a/dlls/riched20/writer.c
+++ b/dlls/riched20/writer.c
@@ -881,11 +881,8 @@ static BOOL ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream,
   ME_Cursor cursor = *start;
   ME_DisplayItem *prev_para = cursor.pPara;
   ME_Cursor endCur = cursor;
-  int actual_chars;
 
-  actual_chars = ME_MoveCursorChars(editor, &endCur, nChars);
-  /* Include the final \r which MoveCursorChars will ignore. */
-  if (actual_chars != nChars) endCur.nOffset++;
+  ME_MoveCursorChars(editor, &endCur, nChars, TRUE);
 
   if (!ME_StreamOutRTFHeader(pStream, dwFormat))
     return FALSE;




More information about the wine-cvs mailing list