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

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-11-03 08:44:43 +00:00 committed by Alexandre Julliard
parent 410dceb939
commit b132d8bf05
3 changed files with 25 additions and 34 deletions

View File

@ -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:
{

View File

@ -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));

View File

@ -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;
ME_Paragraph *para = editor_first_para( editor );
ME_Row *row;
ME_Cursor cursor;
int row_num = 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)
while (para_next( para ) && para_next( para )->nCharOfs <= ofs)
{
if (item == next_para)
break;
item = ME_FindItemFwd(item, diRun);
if (item->member.run.nCharOfs > nOfs)
break;
nRow++;
row_num += para->nRows;
para = para_next( para );
}
}
return nRow;
if (para_next( para ))
{
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 row_num;
}