richedit: Add helpers for setting cursor to start/end of text.
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 5e7bee2..328109d 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -27,6 +27,21 @@
static BOOL
ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs);
+void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor)
+{
+ cursor->pPara = editor->pBuffer->pFirst->member.para.next_para;
+ cursor->pRun = ME_FindItemFwd(cursor->pPara, diRun);
+ cursor->nOffset = 0;
+}
+
+void ME_SetCursorToEnd(ME_TextEditor *editor, ME_Cursor *cursor)
+{
+ cursor->pPara = editor->pBuffer->pLast->member.para.prev_para;
+ cursor->pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
+ cursor->nOffset = 0;
+}
+
+
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
{
*from = ME_GetCursorOfs(&editor->pCursors[0]);
@@ -58,9 +73,9 @@
int ME_GetTextLength(ME_TextEditor *editor)
{
- ME_DisplayItem *pLast = editor->pBuffer->pLast;
- return ME_CharOfsFromRunOfs(editor, pLast->member.para.prev_para,
- ME_FindItemBack(pLast, diRun), 0);
+ ME_Cursor cursor;
+ ME_SetCursorToEnd(editor, &cursor);
+ return ME_GetCursorOfs(&cursor);
}
@@ -111,12 +126,8 @@
/* select all */
if (from == 0 && to == -1)
{
- editor->pCursors[1].pPara = editor->pBuffer->pFirst->member.para.next_para;
- editor->pCursors[1].pRun = ME_FindItemFwd(editor->pCursors[1].pPara, diRun);
- editor->pCursors[1].nOffset = 0;
- editor->pCursors[0].pPara = editor->pBuffer->pLast->member.para.prev_para;
- editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
- editor->pCursors[0].nOffset = 0;
+ ME_SetCursorToStart(editor, &editor->pCursors[1]);
+ ME_SetCursorToEnd(editor, &editor->pCursors[0]);
ME_InvalidateSelection(editor);
ME_ClearTempStyle(editor);
return len + 1;
@@ -164,9 +175,7 @@
if (selectionEnd)
{
- editor->pCursors[0].pPara = editor->pBuffer->pLast->member.para.prev_para;
- editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
- editor->pCursors[0].nOffset = 0;
+ ME_SetCursorToEnd(editor, &editor->pCursors[0]);
editor->pCursors[1] = editor->pCursors[0];
ME_InvalidateSelection(editor);
ME_ClearTempStyle(editor);
@@ -812,12 +821,8 @@
case stDocument:
/* Select everything with cursor anchored from the start of the text */
editor->nSelectionType = stDocument;
- editor->pCursors[1].pPara = editor->pBuffer->pFirst->member.para.next_para;
- editor->pCursors[1].pRun = ME_FindItemFwd(editor->pCursors[1].pPara, diRun);
- editor->pCursors[1].nOffset = 0;
- editor->pCursors[0].pPara = editor->pBuffer->pLast->member.para.prev_para;
- editor->pCursors[0].pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
- editor->pCursors[0].nOffset = 0;
+ ME_SetCursorToStart(editor, &editor->pCursors[1]);
+ ME_SetCursorToEnd(editor, &editor->pCursors[0]);
break;
default: assert(0);
}
@@ -1331,9 +1336,7 @@
if (editor->vert_si.nPos < p->member.row.nHeight)
{
- pCursor->pPara = editor->pBuffer->pFirst->member.para.next_para;
- pCursor->pRun = ME_FindItemFwd(pCursor->pPara, diRun);
- pCursor->nOffset = 0;
+ ME_SetCursorToStart(editor, pCursor);
editor->bCaretAtEnd = FALSE;
/* Native clears seems to clear this x value on page up at the top
* of the text, but not on page down at the end of the text.
@@ -1398,9 +1401,7 @@
if (editor->vert_si.nPos >= y - editor->sizeWindow.cy)
{
- pCursor->pPara = editor->pBuffer->pLast->member.para.prev_para;
- pCursor->pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
- pCursor->nOffset = 0;
+ ME_SetCursorToEnd(editor, pCursor);
editor->bCaretAtEnd = FALSE;
} else {
ME_DisplayItem *pRun = pCursor->pRun;
@@ -1469,9 +1470,7 @@
static void ME_ArrowCtrlHome(ME_TextEditor *editor, ME_Cursor *pCursor)
{
- pCursor->pPara = editor->pBuffer->pFirst->member.para.next_para;
- pCursor->pRun = ME_FindItemFwd(pCursor->pPara, diRun);
- pCursor->nOffset = 0;
+ ME_SetCursorToStart(editor, pCursor);
editor->bCaretAtEnd = FALSE;
}
@@ -1502,10 +1501,7 @@
static void ME_ArrowCtrlEnd(ME_TextEditor *editor, ME_Cursor *pCursor)
{
- pCursor->pPara = editor->pBuffer->pLast->member.para.prev_para;
- pCursor->pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
- assert(pCursor->pRun->member.run.nFlags & MERF_ENDPARA);
- pCursor->nOffset = 0;
+ ME_SetCursorToEnd(editor, pCursor);
editor->bCaretAtEnd = FALSE;
}
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 0eddc0e..fcfd3c4 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1882,7 +1882,7 @@
}
else
{
- ME_CursorFromCharOfs(editor, 0, &start);
+ ME_SetCursorToStart(editor, &start);
nChars = INT_MAX;
}
if (ex->codepage == 1200)
@@ -2623,9 +2623,7 @@
*/
ed->nCursors = 4;
ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
- ed->pCursors[0].pPara = ed->pBuffer->pFirst->member.para.next_para;
- ed->pCursors[0].pRun = ME_FindItemFwd(ed->pCursors[0].pPara, diRun);
- ed->pCursors[0].nOffset = 0;
+ ME_SetCursorToStart(ed, &ed->pCursors[0]);
ed->pCursors[1] = ed->pCursors[0];
ed->pCursors[2] = ed->pCursors[0];
ed->pCursors[3] = ed->pCursors[1];
@@ -2645,7 +2643,7 @@
ed->nUndoMode = umAddToUndo;
ed->nParagraphs = 1;
ed->nLastSelStart = ed->nLastSelEnd = 0;
- ed->pLastSelStartPara = ed->pLastSelEndPara = ME_FindItemFwd(ed->pBuffer->pFirst, diParagraph);
+ ed->pLastSelStartPara = ed->pLastSelEndPara = ed->pCursors[0].pPara;
ed->bHideSelection = FALSE;
ed->pfnWordBreak = NULL;
ed->lpOleCallback = NULL;
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index cbd2a41..2d2e248 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -155,6 +155,8 @@
void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod);
/* caret.c */
+void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor);
+void ME_SetCursorToEnd(ME_TextEditor *editor, ME_Cursor *cursor);
int ME_SetSelection(ME_TextEditor *editor, int from, int to);
void ME_HideCaret(ME_TextEditor *ed);
void ME_ShowCaret(ME_TextEditor *ed);