riched20: Simplify adding the undo items when joining paragraphs.
This commit is contained in:
parent
0333b758b2
commit
ca46d22bca
@ -322,7 +322,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
|
|||||||
ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
|
ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
|
||||||
BOOL keepFirstParaFormat)
|
BOOL keepFirstParaFormat)
|
||||||
{
|
{
|
||||||
ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp;
|
ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp, *pCell = NULL;
|
||||||
int i, shift;
|
int i, shift;
|
||||||
ME_UndoItem *undo = NULL;
|
ME_UndoItem *undo = NULL;
|
||||||
int end_len;
|
int end_len;
|
||||||
@ -353,20 +353,6 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
|
|||||||
ME_PrevRun(&startCur.pPara, &startCur.pRun);
|
ME_PrevRun(&startCur.pPara, &startCur.pRun);
|
||||||
ME_SetCharFormat(editor, &startCur, &endCur, &fmt);
|
ME_SetCharFormat(editor, &startCur, &endCur, &fmt);
|
||||||
|
|
||||||
undo = ME_AddUndoItem(editor, diUndoSplitParagraph, pNext);
|
|
||||||
if (undo)
|
|
||||||
{
|
|
||||||
undo->nStart = pNext->member.para.nCharOfs - end_len;
|
|
||||||
undo->eol_str = pRun->member.run.strText;
|
|
||||||
pRun->member.run.strText = NULL; /* Avoid freeing the string */
|
|
||||||
}
|
|
||||||
if (!keepFirstParaFormat)
|
|
||||||
{
|
|
||||||
ME_AddUndoItem(editor, diUndoSetParagraphFormat, tp);
|
|
||||||
*tp->member.para.pFmt = *pNext->member.para.pFmt;
|
|
||||||
tp->member.para.border = pNext->member.para.border;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!editor->bEmulateVersion10) { /* v4.1 */
|
if (!editor->bEmulateVersion10) { /* v4.1 */
|
||||||
/* Table cell/row properties are always moved over from the removed para. */
|
/* Table cell/row properties are always moved over from the removed para. */
|
||||||
tp->member.para.nFlags = pNext->member.para.nFlags;
|
tp->member.para.nFlags = pNext->member.para.nFlags;
|
||||||
@ -374,35 +360,54 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
|
|||||||
|
|
||||||
/* Remove cell boundary if it is between the end paragraph run and the next
|
/* Remove cell boundary if it is between the end paragraph run and the next
|
||||||
* paragraph display item. */
|
* paragraph display item. */
|
||||||
pTmp = pRun->next;
|
for (pTmp = pRun->next; pTmp != pNext; pTmp = pTmp->next)
|
||||||
while (pTmp != pNext) {
|
{
|
||||||
if (pTmp->type == diCell)
|
if (pTmp->type == diCell)
|
||||||
{
|
{
|
||||||
ME_Cell *pCell = &pTmp->member.cell;
|
pCell = pTmp;
|
||||||
if (undo)
|
|
||||||
{
|
|
||||||
assert(!(undo->di.member.para.nFlags & MEPF_ROWEND));
|
|
||||||
if (!(undo->di.member.para.nFlags & MEPF_ROWSTART))
|
|
||||||
undo->di.member.para.nFlags |= MEPF_CELL;
|
|
||||||
undo->di.member.para.pCell = ALLOC_OBJ(ME_DisplayItem);
|
|
||||||
*undo->di.member.para.pCell = *pTmp;
|
|
||||||
undo->di.member.para.pCell->next = NULL;
|
|
||||||
undo->di.member.para.pCell->prev = NULL;
|
|
||||||
undo->di.member.para.pCell->member.cell.next_cell = NULL;
|
|
||||||
undo->di.member.para.pCell->member.cell.prev_cell = NULL;
|
|
||||||
}
|
|
||||||
ME_Remove(pTmp);
|
|
||||||
if (pCell->prev_cell)
|
|
||||||
pCell->prev_cell->member.cell.next_cell = pCell->next_cell;
|
|
||||||
if (pCell->next_cell)
|
|
||||||
pCell->next_cell->member.cell.prev_cell = pCell->prev_cell;
|
|
||||||
ME_DestroyDisplayItem(pTmp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pTmp = pTmp->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undo = ME_AddUndoItem(editor, diUndoSplitParagraph, pNext);
|
||||||
|
if (undo)
|
||||||
|
{
|
||||||
|
undo->nStart = pNext->member.para.nCharOfs - end_len;
|
||||||
|
undo->eol_str = pRun->member.run.strText;
|
||||||
|
pRun->member.run.strText = NULL; /* Avoid freeing the string */
|
||||||
|
|
||||||
|
if (pCell)
|
||||||
|
{
|
||||||
|
assert(!(undo->di.member.para.nFlags & MEPF_ROWEND));
|
||||||
|
if (!(undo->di.member.para.nFlags & MEPF_ROWSTART))
|
||||||
|
undo->di.member.para.nFlags |= MEPF_CELL;
|
||||||
|
undo->di.member.para.pCell = ALLOC_OBJ(ME_DisplayItem);
|
||||||
|
*undo->di.member.para.pCell = *pCell;
|
||||||
|
undo->di.member.para.pCell->next = NULL;
|
||||||
|
undo->di.member.para.pCell->prev = NULL;
|
||||||
|
undo->di.member.para.pCell->member.cell.next_cell = NULL;
|
||||||
|
undo->di.member.para.pCell->member.cell.prev_cell = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCell)
|
||||||
|
{
|
||||||
|
ME_Remove( pCell );
|
||||||
|
if (pCell->member.cell.prev_cell)
|
||||||
|
pCell->member.cell.prev_cell->member.cell.next_cell = pCell->member.cell.next_cell;
|
||||||
|
if (pCell->member.cell.next_cell)
|
||||||
|
pCell->member.cell.next_cell->member.cell.prev_cell = pCell->member.cell.prev_cell;
|
||||||
|
ME_DestroyDisplayItem( pCell );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keepFirstParaFormat)
|
||||||
|
{
|
||||||
|
ME_AddUndoItem(editor, diUndoSetParagraphFormat, tp);
|
||||||
|
*tp->member.para.pFmt = *pNext->member.para.pFmt;
|
||||||
|
tp->member.para.border = pNext->member.para.border;
|
||||||
|
}
|
||||||
|
|
||||||
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
|
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
|
||||||
|
|
||||||
pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
|
pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user