From aaf29c799121dc388310d06c7fc0ef0512462547 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Mon, 26 Oct 2020 08:46:40 +0000 Subject: [PATCH] riched20: Use row and para helpers for the selection function. Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/riched20/caret.c | 38 ++++++++++++++------------------------ dlls/riched20/editor.h | 3 +++ dlls/riched20/row.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index 5af4cd04d55..650c065dbe0 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -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); } diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 7025ddceea7..e197e3e9a9b 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -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; diff --git a/dlls/riched20/row.c b/dlls/riched20/row.c index ce8de935a19..ba082244cfc 100644 --- a/dlls/riched20/row.c +++ b/dlls/riched20/row.c @@ -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 */