Commit b132d8bf authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Use para and row ptrs in the row number from offset function.

parent 410dceb9
......@@ -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:
{
......
......@@ -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));
......
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment