Commit 8b8e4f89 authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Use ME_Cursor as parameter to ME_SplitRunSimple.

The paragraph needed to be included in the parameters to avoid needing traverse the linked list of display items to find the paragraph.
parent 68b44f74
......@@ -579,10 +579,8 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
}
p = &editor->pCursors[nCursor];
if (p->nOffset) {
ME_SplitRunSimple(editor, p->pRun, p->nOffset);
p = &editor->pCursors[nCursor];
}
if (p->nOffset)
ME_SplitRunSimple(editor, p);
tmp_style = ME_GetInsertStyle(editor, nCursor);
/* ME_SplitParagraph increases style refcount */
tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style, eol_str, 0);
......
......@@ -137,7 +137,7 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset);
int ME_CanJoinRuns(const ME_Run *run1, const ME_Run *run2);
void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p);
ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nChar);
ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nChar);
ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor);
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run);
void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Run *run);
SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, int startx);
......
......@@ -251,9 +251,9 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p)
ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar)
{
ME_TextEditor *editor = wc->context->editor;
ME_DisplayItem *item2 = NULL;
ME_Run *run, *run2;
ME_Paragraph *para = &ME_GetParagraph(item)->member.para;
ME_Paragraph *para = &wc->pPara->member.para;
ME_Cursor cursor = {wc->pPara, item, nVChar};
assert(item->member.run.nCharOfs != -1);
if(TRACE_ON(richedit))
......@@ -268,9 +268,9 @@ ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar
TRACE("Before split: %s(%d, %d)\n", debugstr_w(run->strText->szData),
run->pt.x, run->pt.y);
item2 = ME_SplitRunSimple(editor, item, nVChar);
ME_SplitRunSimple(editor, &cursor);
run2 = &item2->member.run;
run2 = &cursor.pRun->member.run;
ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run2);
......@@ -288,46 +288,45 @@ ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar
debugstr_w(run2->strText->szData), run2->pt.x, run2->pt.y);
}
return item2;
return cursor.pRun;
}
/******************************************************************************
* ME_SplitRunSimple
*
*
* Does the most basic job of splitting a run into two - it does not
* update the positions and extents.
*/
ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nVChar)
* update the positions and extents.
*/
ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor)
{
ME_Run *run = &item->member.run;
ME_DisplayItem *item2;
ME_Run *run2;
ME_DisplayItem *run = cursor->pRun;
ME_DisplayItem *new_run;
int i;
assert(nVChar > 0 && nVChar < run->strText->nLen);
assert(item->type == diRun);
assert(!(item->member.run.nFlags & MERF_NONTEXT));
assert(item->member.run.nCharOfs != -1);
int nOffset = cursor->nOffset;
item2 = ME_MakeRun(run->style,
ME_VSplitString(run->strText, nVChar), run->nFlags&MERF_SPLITMASK);
assert(!(run->member.run.nFlags & MERF_NONTEXT));
item2->member.run.nCharOfs = item->member.run.nCharOfs + nVChar;
new_run = ME_MakeRun(run->member.run.style,
ME_VSplitString(run->member.run.strText, nOffset),
run->member.run.nFlags & MERF_SPLITMASK);
run2 = &item2->member.run;
ME_InsertBefore(item->next, item2);
new_run->member.run.nCharOfs = run->member.run.nCharOfs + nOffset;
cursor->pRun = new_run;
cursor->nOffset = 0;
ME_UpdateRunFlags(editor, run);
ME_UpdateRunFlags(editor, run2);
for (i=0; i<editor->nCursors; i++) {
if (editor->pCursors[i].pRun == item &&
editor->pCursors[i].nOffset >= nVChar) {
assert(item2->type == diRun);
editor->pCursors[i].pRun = item2;
editor->pCursors[i].nOffset -= nVChar;
ME_InsertBefore(run->next, new_run);
ME_UpdateRunFlags(editor, &run->member.run);
ME_UpdateRunFlags(editor, &new_run->member.run);
for (i = 0; i < editor->nCursors; i++) {
if (editor->pCursors[i].pRun == run &&
editor->pCursors[i].nOffset >= nOffset) {
editor->pCursors[i].pRun = new_run;
editor->pCursors[i].nOffset -= nOffset;
}
}
ME_GetParagraph(item)->member.para.nFlags |= MEPF_REWRAP;
return item2;
cursor->pPara->member.para.nFlags |= MEPF_REWRAP;
return run;
}
/******************************************************************************
......@@ -361,12 +360,8 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
ME_DisplayItem *pDI;
ME_UndoItem *pUI;
if (cursor->nOffset) {
/* We're inserting at the middle of the existing run, which means that
* that run must be split. It isn't always necessary, but */
cursor->pRun = ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset);
cursor->nOffset = 0;
}
if (cursor->nOffset)
ME_SplitRunSimple(editor, cursor);
pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
if (pUI) {
......@@ -756,10 +751,8 @@ void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, C
{
/* SplitRunSimple may or may not update the cursors, depending on whether they
* are selection cursors, but we need to make sure they are valid. */
ME_DisplayItem *split_run = start->pRun;
int split_offset = start->nOffset;
start->pRun = ME_SplitRunSimple(editor, split_run, split_offset);
start->nOffset = 0;
ME_DisplayItem *split_run = ME_SplitRunSimple(editor, start);
if (end && end->pRun == split_run)
{
end->pRun = start->pRun;
......@@ -768,12 +761,8 @@ void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, C
}
if (end && end->nOffset)
{
end_run = end->pRun = ME_SplitRunSimple(editor, end->pRun, end->nOffset);
end->nOffset = 0;
} else if (end) {
end_run = end->pRun;
}
ME_SplitRunSimple(editor, end);
end_run = end ? end->pRun : NULL;
run = start->pRun;
para = start->pPara;
......
......@@ -64,10 +64,8 @@ static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor,
ME_Style *pStyle = ME_GetInsertStyle(editor, nCursor);
ME_DisplayItem *tp;
ME_Cursor* cursor = &editor->pCursors[nCursor];
if (cursor->nOffset) {
ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset);
cursor = &editor->pCursors[nCursor];
}
if (cursor->nOffset)
ME_SplitRunSimple(editor, cursor);
tp = ME_SplitParagraph(editor, cursor->pRun, pStyle, eol_str, paraFlags);
ME_ReleaseStyle(pStyle);
......
......@@ -336,7 +336,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
int paraFlags = pItem->member.para.nFlags & (MEPF_ROWSTART|MEPF_CELL|MEPF_ROWEND);
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
if (tmp.nOffset)
tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset);
ME_SplitRunSimple(editor, &tmp);
assert(pUItem->eol_str);
this_para = tmp.pPara;
bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART;
......
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