Commit ecb6c216 authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Store paragraph in cursors.

This prevents some needless searching for the start of the paragraph from a run stored in a cursor. Usually a pointer to the paragraph is already available when the cursor is set anyway.
parent 2033312b
...@@ -263,6 +263,7 @@ typedef struct tagME_TextBuffer ...@@ -263,6 +263,7 @@ typedef struct tagME_TextBuffer
typedef struct tagME_Cursor typedef struct tagME_Cursor
{ {
ME_DisplayItem *pPara;
ME_DisplayItem *pRun; ME_DisplayItem *pRun;
int nOffset; int nOffset;
} ME_Cursor; } ME_Cursor;
......
...@@ -137,7 +137,6 @@ void ME_Repaint(ME_TextEditor *editor) ...@@ -137,7 +137,6 @@ void ME_Repaint(ME_TextEditor *editor)
void ME_UpdateRepaint(ME_TextEditor *editor) void ME_UpdateRepaint(ME_TextEditor *editor)
{ {
/* Should be called whenever the contents of the control have changed */ /* Should be called whenever the contents of the control have changed */
ME_Cursor *pCursor;
BOOL wrappedParagraphs; BOOL wrappedParagraphs;
wrappedParagraphs = ME_WrapMarkedParagraphs(editor); wrappedParagraphs = ME_WrapMarkedParagraphs(editor);
...@@ -145,8 +144,7 @@ void ME_UpdateRepaint(ME_TextEditor *editor) ...@@ -145,8 +144,7 @@ void ME_UpdateRepaint(ME_TextEditor *editor)
ME_UpdateScrollBar(editor); ME_UpdateScrollBar(editor);
/* Ensure that the cursor is visible */ /* Ensure that the cursor is visible */
pCursor = &editor->pCursors[0]; ME_EnsureVisible(editor, &editor->pCursors[0]);
ME_EnsureVisible(editor, pCursor);
/* send EN_CHANGE if the event mask asks for it */ /* send EN_CHANGE if the event mask asks for it */
if(editor->nEventMask & ENM_CHANGE) if(editor->nEventMask & ENM_CHANGE)
...@@ -1226,7 +1224,7 @@ void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor) ...@@ -1226,7 +1224,7 @@ void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor)
{ {
ME_Run *pRun = &pCursor->pRun->member.run; ME_Run *pRun = &pCursor->pRun->member.run;
ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow); ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow);
ME_DisplayItem *pPara = ME_FindItemBack(pCursor->pRun, diParagraph); ME_DisplayItem *pPara = pCursor->pPara;
int x, y, yheight; int x, y, yheight;
assert(pRow); assert(pRow);
......
...@@ -208,7 +208,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -208,7 +208,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
ME_DisplayItem *new_para = ME_MakeDI(diParagraph); ME_DisplayItem *new_para = ME_MakeDI(diParagraph);
ME_DisplayItem *end_run; ME_DisplayItem *end_run;
ME_UndoItem *undo = NULL; ME_UndoItem *undo = NULL;
int ofs; int ofs, i;
ME_DisplayItem *pp; ME_DisplayItem *pp;
int run_flags = MERF_ENDPARA; int run_flags = MERF_ENDPARA;
...@@ -237,13 +237,22 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -237,13 +237,22 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
if (undo) if (undo)
undo->nStart = run_para->member.para.nCharOfs + ofs; undo->nStart = run_para->member.para.nCharOfs + ofs;
/* Update selection cursors to point to the correct paragraph. */
for (i = 0; i < editor->nCursors; i++) {
if (editor->pCursors[i].pPara == run_para &&
run->member.run.nCharOfs <= editor->pCursors[i].pRun->member.run.nCharOfs)
{
editor->pCursors[i].pPara = new_para;
}
}
/* the new paragraph will have a different starting offset, so let's update its runs */ /* the new paragraph will have a different starting offset, so let's update its runs */
pp = run; pp = run;
while(pp->type == diRun) { while(pp->type == diRun) {
pp->member.run.nCharOfs -= ofs; pp->member.run.nCharOfs -= ofs;
pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd); pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd);
} }
new_para->member.para.nCharOfs = ME_GetParagraph(run)->member.para.nCharOfs+ofs; new_para->member.para.nCharOfs = run_para->member.para.nCharOfs + ofs;
new_para->member.para.nCharOfs += eol_str->nLen; new_para->member.para.nCharOfs += eol_str->nLen;
new_para->member.para.nFlags = MEPF_REWRAP; new_para->member.para.nFlags = MEPF_REWRAP;
...@@ -404,12 +413,14 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp, ...@@ -404,12 +413,14 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
assert(pFirstRunInNext->type == diRun); assert(pFirstRunInNext->type == diRun);
/* if some cursor points at end of paragraph, make it point to the first /* Update selection cursors so they don't point to the removed end
run of the next joined paragraph */ * paragraph run, and point to the correct paragraph. */
for (i=0; i<editor->nCursors; i++) { for (i=0; i < editor->nCursors; i++) {
if (editor->pCursors[i].pRun == pRun) { if (editor->pCursors[i].pRun == pRun) {
editor->pCursors[i].pRun = pFirstRunInNext; editor->pCursors[i].pRun = pFirstRunInNext;
editor->pCursors[i].nOffset = 0; editor->pCursors[i].nOffset = 0;
} else if (editor->pCursors[i].pPara == pNext) {
editor->pCursors[i].pPara = tp;
} }
} }
...@@ -516,8 +527,8 @@ ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayIte ...@@ -516,8 +527,8 @@ ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayIte
{ {
ME_Cursor *pEndCursor = &editor->pCursors[1]; ME_Cursor *pEndCursor = &editor->pCursors[1];
*para = ME_GetParagraph(editor->pCursors[0].pRun); *para = editor->pCursors[0].pPara;
*para_end = ME_GetParagraph(editor->pCursors[1].pRun); *para_end = editor->pCursors[1].pPara;
if (*para == *para_end) if (*para == *para_end)
return; return;
......
...@@ -163,7 +163,8 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, ...@@ -163,7 +163,8 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara,
*/ */
void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor)
{ {
ME_RunOfsFromCharOfs(editor, nCharOfs, NULL, &pCursor->pRun, &pCursor->nOffset); ME_RunOfsFromCharOfs(editor, nCharOfs, &pCursor->pPara,
&pCursor->pRun, &pCursor->nOffset);
} }
/****************************************************************************** /******************************************************************************
...@@ -390,8 +391,8 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, ...@@ -390,8 +391,8 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL); pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
if (pUI) { if (pUI) {
pUI->nStart = (ME_GetParagraph(cursor->pRun)->member.para.nCharOfs pUI->nStart = cursor->pPara->member.para.nCharOfs
+ cursor->pRun->member.run.nCharOfs); + cursor->pRun->member.run.nCharOfs;
pUI->nLen = len; pUI->nLen = len;
} }
...@@ -400,7 +401,7 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, ...@@ -400,7 +401,7 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
ME_InsertBefore(cursor->pRun, pDI); ME_InsertBefore(cursor->pRun, pDI);
TRACE("Shift length:%d\n", len); TRACE("Shift length:%d\n", len);
ME_PropagateCharOffset(cursor->pRun, len); ME_PropagateCharOffset(cursor->pRun, len);
ME_GetParagraph(cursor->pRun)->member.para.nFlags |= MEPF_REWRAP; cursor->pPara->member.para.nFlags |= MEPF_REWRAP;
return pDI; return pDI;
} }
...@@ -776,7 +777,7 @@ void ME_SetCharFormat(ME_TextEditor *editor, int nOfs, int nChars, CHARFORMAT2W ...@@ -776,7 +777,7 @@ void ME_SetCharFormat(ME_TextEditor *editor, int nOfs, int nChars, CHARFORMAT2W
if (tmp2.nOffset) if (tmp2.nOffset)
tmp2.pRun = ME_SplitRunSimple(editor, tmp2.pRun, tmp2.nOffset); tmp2.pRun = ME_SplitRunSimple(editor, tmp2.pRun, tmp2.nOffset);
para = ME_GetParagraph(tmp.pRun); para = tmp.pPara;
para->member.para.nFlags |= MEPF_REWRAP; para->member.para.nFlags |= MEPF_REWRAP;
while(tmp.pRun != tmp2.pRun) while(tmp.pRun != tmp2.pRun)
......
...@@ -70,6 +70,7 @@ static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor, ...@@ -70,6 +70,7 @@ static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor,
} }
tp = ME_SplitParagraph(editor, cursor->pRun, pStyle, eol_str, paraFlags); tp = ME_SplitParagraph(editor, cursor->pRun, pStyle, eol_str, paraFlags);
cursor->pPara = tp;
cursor->pRun = ME_FindItemFwd(tp, diRun); cursor->pRun = ME_FindItemFwd(tp, diRun);
return tp; return tp;
} }
...@@ -89,6 +90,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor, ...@@ -89,6 +90,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
ME_DisplayItem *prev_para, *end_para; ME_DisplayItem *prev_para, *end_para;
ME_Cursor savedCursor = editor->pCursors[0]; ME_Cursor savedCursor = editor->pCursors[0];
ME_DisplayItem *startRowPara; ME_DisplayItem *startRowPara;
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -96,7 +98,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor, ...@@ -96,7 +98,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
editor->pCursors[0] = savedCursor; editor->pCursors[0] = savedCursor;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
end_para = ME_GetParagraph(editor->pCursors[0].pRun)->member.para.next_para; end_para = editor->pCursors[0].pPara->member.para.next_para;
prev_para = startRowPara->member.para.next_para; prev_para = startRowPara->member.para.next_para;
para = prev_para->member.para.next_para; para = prev_para->member.para.next_para;
while (para != end_para) while (para != end_para)
...@@ -276,9 +278,9 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars) ...@@ -276,9 +278,9 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars)
ME_Cursor c, c2; ME_Cursor c, c2;
ME_DisplayItem *this_para, *end_para; ME_DisplayItem *this_para, *end_para;
ME_CursorFromCharOfs(editor, nOfs, &c); ME_CursorFromCharOfs(editor, nOfs, &c);
this_para = ME_GetParagraph(c.pRun); this_para = c.pPara;
ME_CursorFromCharOfs(editor, nOfs + *nChars, &c2); ME_CursorFromCharOfs(editor, nOfs + *nChars, &c2);
end_para = ME_GetParagraph(c2.pRun); end_para = c2.pPara;
if (c2.pRun->member.run.nFlags & MERF_ENDPARA) { if (c2.pRun->member.run.nFlags & MERF_ENDPARA) {
/* End offset might be in the middle of the end paragraph run. /* End offset might be in the middle of the end paragraph run.
* If this is the case, then we need to use the next paragraph as the last * If this is the case, then we need to use the next paragraph as the last
...@@ -399,8 +401,9 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ...@@ -399,8 +401,9 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd; ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd;
cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell); cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell);
prevTableEnd = ME_GetTableRowEnd(table_row); prevTableEnd = ME_GetTableRowEnd(table_row);
run = prevTableEnd->member.para.next_para; para = prevTableEnd->member.para.next_para;
run = ME_FindItemFwd(run, diRun); run = ME_FindItemFwd(para, diRun);
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -425,6 +428,7 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ...@@ -425,6 +428,7 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
run = ME_FindItemBack(table_row->member.para.next_para, diRun); run = ME_FindItemBack(table_row->member.para.next_para, diRun);
pFmt = table_row->member.para.pFmt; pFmt = table_row->member.para.pFmt;
assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE); assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE);
editor->pCursors[0].pPara = table_row;
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -474,6 +478,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -474,6 +478,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
para = ME_AppendTableRow(editor, ME_GetTableRowStart(para)); para = ME_AppendTableRow(editor, ME_GetTableRowStart(para));
/* Put cursor at the start of the new table row */ /* Put cursor at the start of the new table row */
para = para->member.para.next_para; para = para->member.para.next_para;
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -483,10 +488,12 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -483,10 +488,12 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
} }
/* Select cell */ /* Select cell */
editor->pCursors[1].pRun = ME_FindItemFwd(cell, diRun); editor->pCursors[1].pRun = ME_FindItemFwd(cell, diRun);
editor->pCursors[1].pPara = ME_GetParagraph(editor->pCursors[1].pRun);
editor->pCursors[1].nOffset = 0; editor->pCursors[1].nOffset = 0;
assert(editor->pCursors[0].pRun); assert(editor->pCursors[0].pRun);
cell = cell->member.cell.next_cell; cell = cell->member.cell.next_cell;
editor->pCursors[0].pRun = ME_FindItemBack(cell, diRun); editor->pCursors[0].pRun = ME_FindItemBack(cell, diRun);
editor->pCursors[0].pPara = ME_GetParagraph(editor->pCursors[0].pRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
assert(editor->pCursors[1].pRun); assert(editor->pCursors[1].pRun);
} else { /* v1.0 - 3.0 */ } else { /* v1.0 - 3.0 */
...@@ -508,6 +515,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -508,6 +515,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
{ {
run = ME_FindItemFwd(para, diRun); run = ME_FindItemFwd(para, diRun);
assert(run); assert(run);
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
i = 1; i = 1;
...@@ -515,6 +523,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -515,6 +523,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
/* Insert table row */ /* Insert table row */
para = ME_AppendTableRow(editor, para->member.para.prev_para); para = ME_AppendTableRow(editor, para->member.para.prev_para);
/* Put cursor at the start of the new table row */ /* Put cursor at the start of the new table row */
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -526,6 +535,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -526,6 +535,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
if (i == 0) if (i == 0)
run = ME_FindItemFwd(run, diRun); run = ME_FindItemFwd(run, diRun);
editor->pCursors[i].pRun = run; editor->pCursors[i].pRun = run;
editor->pCursors[i].pPara = ME_GetParagraph(run);
editor->pCursors[i].nOffset = 0; editor->pCursors[i].nOffset = 0;
} }
} }
...@@ -595,12 +605,13 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow) ...@@ -595,12 +605,13 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
* without a selection. */ * without a selection. */
void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor) void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor)
{ {
ME_DisplayItem *para = ME_GetParagraph(editor->pCursors[0].pRun); ME_DisplayItem *para = editor->pCursors[0].pPara;
if (para == ME_GetParagraph(editor->pCursors[1].pRun) && if (para == editor->pCursors[1].pPara &&
para->member.para.nFlags & MEPF_ROWSTART) { para->member.para.nFlags & MEPF_ROWSTART) {
/* The cursors should not be at the hidden start row paragraph without /* The cursors should not be at the hidden start row paragraph without
* a selection, so the cursor is moved into the first cell. */ * a selection, so the cursor is moved into the first cell. */
para = para->member.para.next_para; para = para->member.para.next_para;
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
......
...@@ -316,7 +316,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) ...@@ -316,7 +316,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
ME_Cursor tmp; ME_Cursor tmp;
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp); ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
/* the only thing that's needed is paragraph offset, so no need to split runs */ /* the only thing that's needed is paragraph offset, so no need to split runs */
ME_JoinParagraphs(editor, ME_GetParagraph(tmp.pRun), TRUE); ME_JoinParagraphs(editor, tmp.pPara, TRUE);
break; break;
} }
case diUndoSplitParagraph: case diUndoSplitParagraph:
...@@ -329,7 +329,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) ...@@ -329,7 +329,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
if (tmp.nOffset) if (tmp.nOffset)
tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset); tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset);
assert(pUItem->eol_str); assert(pUItem->eol_str);
this_para = ME_GetParagraph(tmp.pRun); this_para = tmp.pPara;
bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART; bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART;
if (bFixRowStart) if (bFixRowStart)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment