Commit 4e56a3cd authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Joined paragraph format depends on number of characters deleted.

parent 11c80396
...@@ -267,6 +267,7 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, ...@@ -267,6 +267,7 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs,
{ {
ME_Cursor c; ME_Cursor c;
int shift = 0; int shift = 0;
int totalChars = nChars;
while(nChars > 0) while(nChars > 0)
{ {
...@@ -275,12 +276,15 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, ...@@ -275,12 +276,15 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs,
run = &c.pRun->member.run; run = &c.pRun->member.run;
if (run->nFlags & MERF_ENDPARA) { if (run->nFlags & MERF_ENDPARA) {
int eollen = run->nCR + run->nLF; int eollen = run->nCR + run->nLF;
BOOL keepFirstParaFormat;
if (!ME_FindItemFwd(c.pRun, diParagraph)) if (!ME_FindItemFwd(c.pRun, diParagraph))
{ {
return; return;
} }
ME_JoinParagraphs(editor, ME_GetParagraph(c.pRun)); keepFirstParaFormat = (totalChars == nChars && nChars <= eollen &&
run->nCharOfs);
ME_JoinParagraphs(editor, ME_GetParagraph(c.pRun), keepFirstParaFormat);
/* ME_SkipAndPropagateCharOffset(p->pRun, shift); */ /* ME_SkipAndPropagateCharOffset(p->pRun, shift); */
ME_CheckCharOffsets(editor); ME_CheckCharOffsets(editor);
nChars -= (eollen < nChars) ? eollen : nChars; nChars -= (eollen < nChars) ? eollen : nChars;
......
...@@ -218,7 +218,8 @@ ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run); ...@@ -218,7 +218,8 @@ ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run);
void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end); void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end);
void ME_MakeFirstParagraph(ME_TextEditor *editor); void ME_MakeFirstParagraph(ME_TextEditor *editor);
ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *rp, ME_Style *style, int numCR, int numLF); ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *rp, ME_Style *style, int numCR, int numLF);
ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp); ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
BOOL keepFirstParaFormat);
void ME_DumpParaStyle(ME_Paragraph *s); void ME_DumpParaStyle(ME_Paragraph *s);
void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]); void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]);
void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt); void ME_SetParaFormat(ME_TextEditor *editor, ME_DisplayItem *para, const PARAFORMAT2 *pFmt);
......
...@@ -167,7 +167,8 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME ...@@ -167,7 +167,8 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME
/* join tp with tp->member.para.next_para, keeping tp's style; this /* join tp with tp->member.para.next_para, keeping tp's style; this
* is consistent with the original */ * is consistent with the original */
ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
BOOL keepFirstParaFormat)
{ {
ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp; ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp;
int i, shift; int i, shift;
...@@ -195,14 +196,17 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) ...@@ -195,14 +196,17 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
ME_InitCharFormat2W(&fmt); ME_InitCharFormat2W(&fmt);
ME_SetCharFormat(editor, pNext->member.para.nCharOfs - end_len, end_len, &fmt); ME_SetCharFormat(editor, pNext->member.para.nCharOfs - end_len, end_len, &fmt);
} }
undo = ME_AddUndoItem(editor, diUndoSplitParagraph, NULL); undo = ME_AddUndoItem(editor, diUndoSplitParagraph, pNext);
if (undo) if (undo)
{ {
undo->nStart = pNext->member.para.nCharOfs - end_len; undo->nStart = pNext->member.para.nCharOfs - end_len;
undo->nCR = pRun->member.run.nCR; undo->nCR = pRun->member.run.nCR;
undo->nLF = pRun->member.run.nLF; undo->nLF = pRun->member.run.nLF;
assert(pNext->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); }
*undo->di.member.para.pFmt = *pNext->member.para.pFmt; if (!keepFirstParaFormat)
{
ME_AddUndoItem(editor, diUndoSetParagraphFormat, tp);
*tp->member.para.pFmt = *pNext->member.para.pFmt;
} }
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len; shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
......
...@@ -89,10 +89,9 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp ...@@ -89,10 +89,9 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp
case diUndoJoinParagraphs: case diUndoJoinParagraphs:
break; break;
case diUndoSplitParagraph: case diUndoSplitParagraph:
assert(pdi->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2); pItem->member.para.pFmt = ALLOC_OBJ(PARAFORMAT2);
pItem->member.para.pFmt->cbSize = sizeof(PARAFORMAT2); *pItem->member.para.pFmt = *pdi->member.para.pFmt;
pItem->member.para.pFmt->dwMask = 0;
break; break;
default: default:
assert(0 == "AddUndoItem, unsupported item type"); assert(0 == "AddUndoItem, unsupported item type");
...@@ -282,8 +281,11 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) ...@@ -282,8 +281,11 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
case diUndoSetParagraphFormat: case diUndoSetParagraphFormat:
{ {
ME_Cursor tmp; ME_Cursor tmp;
ME_DisplayItem *para;
ME_CursorFromCharOfs(editor, pItem->member.para.nCharOfs, &tmp); ME_CursorFromCharOfs(editor, pItem->member.para.nCharOfs, &tmp);
ME_SetParaFormat(editor, ME_FindItemBack(tmp.pRun, diParagraph), pItem->member.para.pFmt); para = ME_FindItemBack(tmp.pRun, diParagraph);
ME_AddUndoItem(editor, diUndoSetParagraphFormat, para);
*para->member.para.pFmt = *pItem->member.para.pFmt;
break; break;
} }
case diUndoSetCharFormat: case diUndoSetCharFormat:
...@@ -306,7 +308,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) ...@@ -306,7 +308,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)); ME_JoinParagraphs(editor, ME_GetParagraph(tmp.pRun), TRUE);
break; break;
} }
case diUndoSplitParagraph: case diUndoSplitParagraph:
......
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