riched20: Avoid an unnecessary string duplication.
This commit is contained in:
parent
2cb3df606f
commit
7a27ffb28c
@ -361,6 +361,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ME_Cursor cursor;
|
ME_Cursor cursor;
|
||||||
|
ME_UndoItem *undo;
|
||||||
int nCharsToDelete = min(nChars, c.nOffset);
|
int nCharsToDelete = min(nChars, c.nOffset);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -378,25 +379,15 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
|
|||||||
nCharsToDelete, nChars, c.nOffset,
|
nCharsToDelete, nChars, c.nOffset,
|
||||||
debugstr_w(run->strText->szData), run->strText->nLen);
|
debugstr_w(run->strText->szData), run->strText->nLen);
|
||||||
|
|
||||||
if (!c.nOffset && run->strText->nLen == nCharsToDelete)
|
undo = ME_AddUndoItem(editor, diUndoInsertRun, c.pRun);
|
||||||
|
if (undo)
|
||||||
{
|
{
|
||||||
/* undo = reinsert whole run */
|
|
||||||
/* nOfs is a character offset (from the start of the document
|
/* nOfs is a character offset (from the start of the document
|
||||||
to the current (deleted) run */
|
to the current (deleted) run */
|
||||||
ME_UndoItem *pUndo = ME_AddUndoItem(editor, diUndoInsertRun, c.pRun);
|
undo->di.member.run.nCharOfs = nOfs + nChars;
|
||||||
if (pUndo)
|
undo->di.member.run.strText = ME_MakeStringN(run->strText->szData + c.nOffset, nCharsToDelete);
|
||||||
pUndo->di.member.run.nCharOfs = nOfs+nChars;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* undo = reinsert partial run */
|
|
||||||
ME_UndoItem *pUndo = ME_AddUndoItem(editor, diUndoInsertRun, c.pRun);
|
|
||||||
if (pUndo) {
|
|
||||||
ME_DestroyString(pUndo->di.member.run.strText);
|
|
||||||
pUndo->di.member.run.nCharOfs = nOfs+nChars;
|
|
||||||
pUndo->di.member.run.strText = ME_MakeStringN(run->strText->szData+c.nOffset, nCharsToDelete);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE("Post deletion string: %s (%d)\n", debugstr_w(run->strText->szData), run->strText->nLen);
|
TRACE("Post deletion string: %s (%d)\n", debugstr_w(run->strText->szData), run->strText->nLen);
|
||||||
TRACE("Shift value: %d\n", shift);
|
TRACE("Shift value: %d\n", shift);
|
||||||
ME_StrDeleteV(run->strText, c.nOffset, nCharsToDelete);
|
ME_StrDeleteV(run->strText, c.nOffset, nCharsToDelete);
|
||||||
|
@ -73,7 +73,7 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp
|
|||||||
case diUndoInsertRun:
|
case diUndoInsertRun:
|
||||||
assert(pdi);
|
assert(pdi);
|
||||||
pItem->member.run = pdi->member.run;
|
pItem->member.run = pdi->member.run;
|
||||||
pItem->member.run.strText = ME_StrDup(pItem->member.run.strText);
|
pItem->member.run.strText = NULL;
|
||||||
ME_AddRefStyle(pItem->member.run.style);
|
ME_AddRefStyle(pItem->member.run.style);
|
||||||
if (pdi->member.run.ole_obj)
|
if (pdi->member.run.ole_obj)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user