richedit: Avoid notifying parent window in improper state.

ME_CommitUndo and ME_CommitCoalescingUndo call ME_SendSelChange, which
may notify the parent window that the selection has changed, therefore
should generally be called after wrapping the text. Otherwise, the parent
window may send a message to the editor and cause an assertion failure.
This commit is contained in:
Dylan Smith 2010-05-14 20:11:28 -04:00 committed by Alexandre Julliard
parent d728169d97
commit 049cf5aca0
2 changed files with 32 additions and 20 deletions

View File

@ -317,8 +317,8 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
break; break;
stream->dwSize = 0; stream->dwSize = 0;
} while(1); } while(1);
ME_CommitUndo(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
return 0; return 0;
} }
@ -2105,10 +2105,16 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
return TRUE; return TRUE;
case VK_BACK: case VK_BACK:
case VK_DELETE: case VK_DELETE:
{
int saved_nEventMask;
editor->nUDArrowX = -1; editor->nUDArrowX = -1;
/* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */ /* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
if (editor->styleFlags & ES_READONLY) if (editor->styleFlags & ES_READONLY)
return FALSE; return FALSE;
/* Prevent calling ME_SendSelChange until after wrapping the
* text due to text deletion. */
saved_nEventMask = editor->nEventMask;
editor->nEventMask = 0;
if (ME_IsSelection(editor)) if (ME_IsSelection(editor))
{ {
ME_DeleteSelection(editor); ME_DeleteSelection(editor);
@ -2136,12 +2142,18 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
ME_CommitCoalescingUndo(editor); ME_CommitCoalescingUndo(editor);
} }
else else
{
editor->nEventMask = saved_nEventMask;
return TRUE; return TRUE;
}
editor->nEventMask = saved_nEventMask;
ME_MoveCursorFromTableRowStartParagraph(editor); ME_MoveCursorFromTableRowStartParagraph(editor);
ME_UpdateSelectionLinkAttribute(editor); ME_UpdateSelectionLinkAttribute(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_SendSelChange(editor);
ME_SendRequestResize(editor, FALSE); ME_SendRequestResize(editor, FALSE);
return TRUE; return TRUE;
}
case VK_RETURN: case VK_RETURN:
if (editor->bDialogMode) if (editor->bDialogMode)
{ {
@ -2193,9 +2205,9 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
ME_CommitUndo(editor);
ME_CheckTablesForCorruption(editor); ME_CheckTablesForCorruption(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
return TRUE; return TRUE;
} }
else if (para == editor->pCursors[1].pPara && else if (para == editor->pCursors[1].pPara &&
@ -2218,9 +2230,9 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART; para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART;
ME_CommitCoalescingUndo(editor);
ME_CheckTablesForCorruption(editor); ME_CheckTablesForCorruption(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitCoalescingUndo(editor);
return TRUE; return TRUE;
} }
} else { /* v1.0 - 3.0 */ } else { /* v1.0 - 3.0 */
@ -2236,8 +2248,8 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
ME_CommitCoalescingUndo(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitCoalescingUndo(editor);
return TRUE; return TRUE;
} }
} else { } else {
@ -2263,8 +2275,8 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
} }
ME_CommitCoalescingUndo(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitCoalescingUndo(editor);
return TRUE; return TRUE;
} }
} }
@ -2278,11 +2290,11 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
else else
ME_InsertTextFromCursor(editor, 0, &endl, 1, style); ME_InsertTextFromCursor(editor, 0, &endl, 1, style);
ME_ReleaseStyle(style); ME_ReleaseStyle(style);
ME_CommitCoalescingUndo(editor);
SetCursor(NULL); SetCursor(NULL);
ME_UpdateSelectionLinkAttribute(editor); ME_UpdateSelectionLinkAttribute(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitCoalescingUndo(editor);
} }
return TRUE; return TRUE;
} }
@ -2320,8 +2332,8 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
if (result && nKey == 'X') if (result && nKey == 'X')
{ {
ME_InternalDeleteText(editor, selStart, nChars, FALSE); ME_InternalDeleteText(editor, selStart, nChars, FALSE);
ME_CommitUndo(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
} }
return result; return result;
} }
@ -2446,12 +2458,12 @@ static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode,
ME_ContinueCoalescingTransaction(editor); ME_ContinueCoalescingTransaction(editor);
ME_InsertTextFromCursor(editor, 0, &wstr, 1, style); ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
ME_ReleaseStyle(style); ME_ReleaseStyle(style);
ME_CommitCoalescingUndo(editor);
ITextHost_TxSetCursor(editor->texthost, NULL, FALSE); ITextHost_TxSetCursor(editor->texthost, NULL, FALSE);
} }
ME_UpdateSelectionLinkAttribute(editor); ME_UpdateSelectionLinkAttribute(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitCoalescingUndo(editor);
} }
return 0; return 0;
} }
@ -3295,13 +3307,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_SetCursorToStart(editor, &cursor); ME_SetCursorToStart(editor, &cursor);
ME_UpdateLinkAttribute(editor, &cursor, INT_MAX); ME_UpdateLinkAttribute(editor, &cursor, INT_MAX);
} }
ME_UpdateRepaint(editor);
ME_CommitUndo(editor); ME_CommitUndo(editor);
if (!(pStruct->flags & ST_KEEPUNDO)) if (!(pStruct->flags & ST_KEEPUNDO))
{ {
editor->nModifyStep = oldModify; editor->nModifyStep = oldModify;
ME_EmptyUndoStack(editor); ME_EmptyUndoStack(editor);
} }
ME_UpdateRepaint(editor);
return len; return len;
} }
case EM_SETBKGNDCOLOR: case EM_SETBKGNDCOLOR:
@ -3382,13 +3394,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_SetSelectionCharFormat(editor, p); ME_SetSelectionCharFormat(editor, p);
if (bRepaint) editor->nModifyStep = 1; if (bRepaint) editor->nModifyStep = 1;
} }
ME_CommitUndo(editor);
if (bRepaint) if (bRepaint)
{ {
ME_WrapMarkedParagraphs(editor); ME_WrapMarkedParagraphs(editor);
ME_UpdateScrollBar(editor); ME_UpdateScrollBar(editor);
ME_Repaint(editor); ME_Repaint(editor);
} }
ME_CommitUndo(editor);
return 1; return 1;
} }
case EM_GETCHARFORMAT: case EM_GETCHARFORMAT:
@ -3461,8 +3473,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
int from, to; int from, to;
int nStartCursor = ME_GetSelectionOfs(editor, &from, &to); int nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE); ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
ME_CommitUndo(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
return 0; return 0;
} }
case EM_REPLACESEL: case EM_REPLACESEL:
@ -3486,11 +3498,11 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
if (len>0 && wszText[len-1] == '\n') if (len>0 && wszText[len-1] == '\n')
ME_ClearTempStyle(editor); ME_ClearTempStyle(editor);
ME_EndToUnicode(unicode, wszText); ME_EndToUnicode(unicode, wszText);
ME_CommitUndo(editor);
ME_UpdateSelectionLinkAttribute(editor); ME_UpdateSelectionLinkAttribute(editor);
ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
if (!wParam) if (!wParam)
ME_EmptyUndoStack(editor); ME_EmptyUndoStack(editor);
ME_UpdateRepaint(editor);
return len; return len;
} }
case EM_SCROLLCARET: case EM_SCROLLCARET:
@ -3514,10 +3526,10 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_SetCharFormat(editor, &start, NULL, &fmt); ME_SetCharFormat(editor, &start, NULL, &fmt);
ME_SetDefaultCharFormat(editor, &fmt); ME_SetDefaultCharFormat(editor, &fmt);
ME_CommitUndo(editor);
ME_MarkAllForWrapping(editor); ME_MarkAllForWrapping(editor);
ME_WrapMarkedParagraphs(editor); ME_WrapMarkedParagraphs(editor);
ME_UpdateScrollBar(editor); ME_UpdateScrollBar(editor);
ME_CommitUndo(editor);
if (bRepaint) if (bRepaint)
ME_Repaint(editor); ME_Repaint(editor);
return 0; return 0;
@ -3564,9 +3576,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_UpdateLinkAttribute(editor, &cursor, INT_MAX); ME_UpdateLinkAttribute(editor, &cursor, INT_MAX);
ME_SetSelection(editor, 0, 0); ME_SetSelection(editor, 0, 0);
editor->nModifyStep = 0; editor->nModifyStep = 0;
ME_UpdateRepaint(editor);
ME_CommitUndo(editor); ME_CommitUndo(editor);
ME_EmptyUndoStack(editor); ME_EmptyUndoStack(editor);
ME_UpdateRepaint(editor);
return 1; return 1;
} }
case EM_CANPASTE: case EM_CANPASTE:
@ -3591,8 +3603,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
if (ME_Copy(editor, selStart, nChars) && msg == WM_CUT) if (ME_Copy(editor, selStart, nChars) && msg == WM_CUT)
{ {
ME_InternalDeleteText(editor, selStart, nChars, FALSE); ME_InternalDeleteText(editor, selStart, nChars, FALSE);
ME_CommitUndo(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
} }
return 0; return 0;
} }
@ -3927,9 +3939,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
} }
} }
ME_CommitUndo(editor);
ME_WrapMarkedParagraphs(editor); ME_WrapMarkedParagraphs(editor);
ME_MoveCaret(editor); ME_MoveCaret(editor);
ME_CommitUndo(editor);
return 0; return 0;
} }
case WM_DESTROY: case WM_DESTROY:
@ -4245,8 +4257,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
{ {
editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]); editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]);
ME_DeleteSelection(editor); ME_DeleteSelection(editor);
ME_CommitUndo(editor);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
return 0; return 0;
} }
case WM_IME_COMPOSITION: case WM_IME_COMPOSITION:
@ -4256,7 +4268,6 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_Style *style = ME_GetInsertStyle(editor, 0); ME_Style *style = ME_GetInsertStyle(editor, 0);
hIMC = ITextHost_TxImmGetContext(editor->texthost); hIMC = ITextHost_TxImmGetContext(editor->texthost);
ME_DeleteSelection(editor); ME_DeleteSelection(editor);
ME_CommitUndo(editor);
ME_SaveTempStyle(editor); ME_SaveTempStyle(editor);
if (lParam & GCS_RESULTSTR) if (lParam & GCS_RESULTSTR)
{ {
@ -4285,6 +4296,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
} }
ME_ReleaseStyle(style); ME_ReleaseStyle(style);
ME_UpdateRepaint(editor); ME_UpdateRepaint(editor);
ME_CommitUndo(editor);
return 0; return 0;
} }
case WM_IME_ENDCOMPOSITION: case WM_IME_ENDCOMPOSITION:

View File

@ -390,8 +390,8 @@ IRichEditOle_fnInsertObject(IRichEditOle *me, REOBJECT *reo)
if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER; if (reo->cbStruct < sizeof(*reo)) return STG_E_INVALIDPARAMETER;
ME_InsertOLEFromCursor(This->editor, reo, 0); ME_InsertOLEFromCursor(This->editor, reo, 0);
ME_CommitUndo(This->editor);
ME_UpdateRepaint(This->editor); ME_UpdateRepaint(This->editor);
ME_CommitUndo(This->editor);
return S_OK; return S_OK;
} }