richedit: Directly get start and end of text on Ctrl-Home or Ctrl-End.

Dylan Smith dylan.ah.smith at gmail.com
Sat Feb 7 12:20:31 CST 2009


Previously it found the start or end by traversing the linked lists of
run, rows, paragraphs, and cells from the current position of the
cursors.  Clearly it is better to get the start or end directly to make
it a constant time operation.

The bCaretAtEnd variable should also be set to FALSE, even on
ArrowCtrlHome, although it only has an affect when it is at a line break
created from wrapping.  This is why the ME_ArrowEnd code with the FIXME
comment is valid.
---
 dlls/riched20/caret.c |   28 +++++++++-------------------
 1 files changed, 9 insertions(+), 19 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 46e16d4..edbdf46 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -1436,32 +1436,26 @@ static void ME_ArrowHome(ME_TextEditor *editor, ME_Cursor *pCursor)
 
 static void ME_ArrowCtrlHome(ME_TextEditor *editor, ME_Cursor *pCursor)
 {
-  ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diTextStart);
-  if (pRow) {
-    ME_DisplayItem *pRun = ME_FindItemFwd(pRow, diRun);
-    if (pRun) {
-      pCursor->pRun = pRun;
-      pCursor->nOffset = 0;
-    }
-  }
+  pCursor->pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun);
+  pCursor->nOffset = 0;
+  editor->bCaretAtEnd = FALSE;
 }
 
 static void ME_ArrowEnd(ME_TextEditor *editor, ME_Cursor *pCursor)
 {
   ME_DisplayItem *pRow;
-  
+
   if (editor->bCaretAtEnd && !pCursor->nOffset)
     return;
-  
+
   pRow = ME_FindItemFwd(pCursor->pRun, diStartRowOrParagraphOrEnd);
   assert(pRow);
   if (pRow->type == diStartRow) {
-    /* FIXME WTF was I thinking about here ? */
     ME_DisplayItem *pRun = ME_FindItemFwd(pRow, diRun);
     assert(pRun);
     pCursor->pRun = pRun;
     pCursor->nOffset = 0;
-    editor->bCaretAtEnd = 1;
+    editor->bCaretAtEnd = TRUE;
     return;
   }
   pCursor->pRun = ME_FindItemBack(pRow, diRun);
@@ -1469,15 +1463,11 @@ static void ME_ArrowEnd(ME_TextEditor *editor, ME_Cursor *pCursor)
   pCursor->nOffset = 0;
   editor->bCaretAtEnd = FALSE;
 }
-      
+
 static void ME_ArrowCtrlEnd(ME_TextEditor *editor, ME_Cursor *pCursor)
 {
-  ME_DisplayItem *p = ME_FindItemFwd(pCursor->pRun, diTextEnd);
-  assert(p);
-  p = ME_FindItemBack(p, diRun);
-  assert(p);
-  assert(p->member.run.nFlags & MERF_ENDPARA);
-  pCursor->pRun = p;
+  pCursor->pRun = ME_FindItemBack(editor->pBuffer->pLast, diRun);
+  assert(pCursor->pRun->member.run.nFlags & MERF_ENDPARA);
   pCursor->nOffset = 0;
   editor->bCaretAtEnd = FALSE;
 }


More information about the wine-patches mailing list