[PATCH 4/5] riched20: Use para and row ptrs in the row number from offset function.

Huw Davies huw at codeweavers.com
Tue Nov 3 02:44:43 CST 2020


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/riched20/editor.c | 12 ++++-------
 dlls/riched20/editor.h |  2 +-
 dlls/riched20/row.c    | 47 +++++++++++++++++++-----------------------
 3 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 168dc51d827..41906d28e4c 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -4312,17 +4312,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   }
   case EM_LINEFROMCHAR:
   {
-    if (wParam == -1)
-      return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
-    else
-      return ME_RowNumberFromCharOfs(editor, wParam);
+    if (wParam == -1) wParam = ME_GetCursorOfs( editor->pCursors + 1 );
+    return row_number_from_char_ofs( editor, wParam );
   }
   case EM_EXLINEFROMCHAR:
   {
-    if (lParam == -1)
-      return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
-    else    
-      return ME_RowNumberFromCharOfs(editor, lParam);
+    if (lParam == -1) lParam = ME_GetCursorOfs( editor->pCursors + 1 );
+    return row_number_from_char_ofs( editor, lParam );
   }
   case EM_LINEINDEX:
   {
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index e5d580846d0..e884cbee2f3 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -118,7 +118,7 @@ ME_Row *row_from_cursor( ME_Cursor *cursor ) DECLSPEC_HIDDEN;
 ME_Row *row_from_row_number( ME_TextEditor *editor, int row_num ) DECLSPEC_HIDDEN;
 ME_Row *row_next( ME_Row *row ) DECLSPEC_HIDDEN;
 ME_Run *row_next_run( ME_Row *row, ME_Run *run ) DECLSPEC_HIDDEN;
-int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
+int row_number_from_char_ofs( ME_TextEditor *editor, int ofs ) DECLSPEC_HIDDEN;
 static inline ME_DisplayItem *row_get_di( ME_Row *row )
 {
     return (ME_DisplayItem *)((ptrdiff_t)row - offsetof(ME_DisplayItem, member));
diff --git a/dlls/riched20/row.c b/dlls/riched20/row.c
index a12a8c7449b..9a87cf27fb5 100644
--- a/dlls/riched20/row.c
+++ b/dlls/riched20/row.c
@@ -102,33 +102,28 @@ ME_Row *row_from_row_number( ME_TextEditor *editor, int row_num )
 }
 
 
-int
-ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs)
+int row_number_from_char_ofs( ME_TextEditor *editor, int ofs )
 {
-  ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
-  int nRow = 0;
-
-  while (item->type == diParagraph &&
-         item->member.para.next_para->member.para.nCharOfs <= nOfs)
-  {
-    nRow += item->member.para.nRows;
-    item = item->member.para.next_para;
-  }
-  if (item->type == diParagraph)
-  {
-    ME_DisplayItem *next_para = item->member.para.next_para;
-
-    nOfs -= item->member.para.nCharOfs;
-    item = ME_FindItemFwd(item, diRun);
-    while ((item = ME_FindItemFwd(item, diStartRowOrParagraph)) != NULL)
+    ME_Paragraph *para = editor_first_para( editor );
+    ME_Row *row;
+    ME_Cursor cursor;
+    int row_num = 0;
+
+    while (para_next( para ) && para_next( para )->nCharOfs <= ofs)
+    {
+        row_num += para->nRows;
+        para = para_next( para );
+    }
+
+    if (para_next( para ))
     {
-      if (item == next_para)
-        break;
-      item = ME_FindItemFwd(item, diRun);
-      if (item->member.run.nCharOfs > nOfs)
-        break;
-      nRow++;
+        for (row = para_first_row( para ); row; row = row_next( row ))
+        {
+            row_end_cursor( row, &cursor, TRUE );
+            if (ME_GetCursorOfs( &cursor ) > ofs ) break;
+            row_num++;
+        }
     }
-  }
-  return nRow;
+
+    return row_num;
 }
-- 
2.23.0




More information about the wine-devel mailing list