diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp
index b3360159ae6..909fbca2072 100644
--- a/mozilla/editor/base/nsHTMLEditor.cpp
+++ b/mozilla/editor/base/nsHTMLEditor.cpp
@@ -4473,6 +4473,15 @@ nsHTMLEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivat
return NS_ERROR_NULL_POINTER;
nsCOMPtr caretP;
+ // workaround for windows ime bug 23558: we get every ime event twice.
+ // for escape keypress, this causes an empty string to be passed
+ // twice, which freaks out the editor. This is to detect and aviod that
+ // situation:
+ if (aCompositionString.IsEmpty() && !mIMETextNode)
+ {
+ return NS_OK;
+ }
+
nsCOMPtr selection;
nsresult result = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(result)) return result;
@@ -4490,6 +4499,12 @@ nsHTMLEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivat
ps->GetCaret(getter_AddRefs(caretP));
caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
+ // second part of 23558 fix:
+ if (aCompositionString.IsEmpty())
+ {
+ mIMETextNode = nsnull;
+ }
+
return result;
}
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
index b3360159ae6..909fbca2072 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
@@ -4473,6 +4473,15 @@ nsHTMLEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivat
return NS_ERROR_NULL_POINTER;
nsCOMPtr caretP;
+ // workaround for windows ime bug 23558: we get every ime event twice.
+ // for escape keypress, this causes an empty string to be passed
+ // twice, which freaks out the editor. This is to detect and aviod that
+ // situation:
+ if (aCompositionString.IsEmpty() && !mIMETextNode)
+ {
+ return NS_OK;
+ }
+
nsCOMPtr selection;
nsresult result = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(result)) return result;
@@ -4490,6 +4499,12 @@ nsHTMLEditor::SetCompositionString(const nsString& aCompositionString, nsIPrivat
ps->GetCaret(getter_AddRefs(caretP));
caretP->GetWindowRelativeCoordinates(aReply->mCursorPosition,aReply->mCursorIsCollapsed);
+ // second part of 23558 fix:
+ if (aCompositionString.IsEmpty())
+ {
+ mIMETextNode = nsnull;
+ }
+
return result;
}