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