riched20: Use row and para helpers for the selection 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-10-26 08:46:40 +00:00 committed by Alexandre Julliard
parent 0fda889f35
commit aaf29c7991
3 changed files with 46 additions and 24 deletions

View file

@ -818,38 +818,28 @@ ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType)
editor->pCursors[1] = editor->pCursors[0];
ME_MoveCursorWords(editor, &editor->pCursors[1], -1);
break;
case stLine:
case stParagraph:
{
ME_DisplayItem *pItem;
ME_DIType fwdSearchType, backSearchType;
if (selectionType == stParagraph) {
backSearchType = diParagraph;
fwdSearchType = diParagraphOrEnd;
} else {
backSearchType = diStartRow;
fwdSearchType = diStartRowOrParagraphOrEnd;
}
pItem = ME_FindItemFwd(editor->pCursors[0].pRun, fwdSearchType);
assert(pItem);
if (pItem->type == diTextEnd)
editor->pCursors[0].pRun = ME_FindItemBack(pItem, diRun);
else
editor->pCursors[0].pRun = ME_FindItemFwd(pItem, diRun);
editor->pCursors[0].pPara = ME_GetParagraph(editor->pCursors[0].pRun);
editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0];
pItem = ME_FindItemBack(pItem, backSearchType);
editor->pCursors[1].pRun = ME_FindItemFwd(pItem, diRun);
editor->pCursors[1].pPara = ME_GetParagraph(editor->pCursors[1].pRun);
editor->pCursors[0].pRun = run_get_di( para_end_run( &editor->pCursors[0].pPara->member.para ) );
editor->pCursors[0].pPara = para_get_di( editor->pCursors[0].pRun->member.run.para );
editor->pCursors[0].nOffset = editor->pCursors[0].pRun->member.run.len;
editor->pCursors[1].pRun = run_get_di( para_first_run( &editor->pCursors[1].pPara->member.para ) );
editor->pCursors[1].nOffset = 0;
break;
case stLine:
{
ME_Row *row = row_from_cursor( editor->pCursors );
row_first_cursor( row, editor->pCursors + 1 );
row_end_cursor( row, editor->pCursors, TRUE );
break;
}
case stDocument:
/* Select everything with cursor anchored from the start of the text */
editor->nSelectionType = stDocument;
ME_SetCursorToStart(editor, &editor->pCursors[1]);
ME_SetCursorToEnd(editor, &editor->pCursors[0], FALSE);
ME_SetCursorToEnd(editor, &editor->pCursors[0], TRUE);
break;
default: assert(0);
}

View file

@ -111,7 +111,10 @@ int ME_ReverseFindNonWhitespaceV(const ME_String *s, int nVChar) DECLSPEC_HIDDEN
int ME_ReverseFindWhitespaceV(const ME_String *s, int nVChar) DECLSPEC_HIDDEN;
/* row.c */
void row_end_cursor( ME_Row *row, ME_Cursor *cursor, BOOL include_eop ) DECLSPEC_HIDDEN;
void row_first_cursor( ME_Row *row, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
ME_Run *row_first_run( ME_Row *row ) DECLSPEC_HIDDEN;
ME_Row *row_from_cursor( ME_Cursor *cursor ) DECLSPEC_HIDDEN;
ME_Row *row_next( ME_Row *row ) DECLSPEC_HIDDEN;
ME_Run *row_next_run( ME_Row *row, ME_Run *run ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) DECLSPEC_HIDDEN;

View file

@ -53,6 +53,35 @@ ME_Run *row_next_run( ME_Row *row, ME_Run *run )
return &item->member.run;
}
ME_Row *row_from_cursor( ME_Cursor *cursor )
{
ME_DisplayItem *item;
item = ME_FindItemBack( cursor->pRun, diStartRow );
return &item->member.row;
}
void row_first_cursor( ME_Row *row, ME_Cursor *cursor )
{
ME_DisplayItem *item;
item = ME_FindItemFwd( row_get_di( row ), diRun );
cursor->pRun = item;
cursor->pPara = para_get_di( cursor->pRun->member.run.para );
cursor->nOffset = 0;
}
void row_end_cursor( ME_Row *row, ME_Cursor *cursor, BOOL include_eop )
{
ME_DisplayItem *item, *run;
item = ME_FindItemFwd( row_get_di( row ), diStartRowOrParagraphOrEnd );
run = ME_FindItemBack( item, diRun );
cursor->pRun = run;
cursor->pPara = para_get_di( cursor->pRun->member.run.para );
cursor->nOffset = (item->type == diStartRow || include_eop) ? cursor->pRun->member.run.len : 0;
}
/* I'm sure these functions would simplify some code in caret ops etc,
* I just didn't remember them when I wrote that code
*/