From 3fc8df7cf513eba0df81ce12d036f7398606c0b9 Mon Sep 17 00:00:00 2001 From: "ftang%netscape.com" Date: Thu, 7 Mar 2002 14:34:35 +0000 Subject: [PATCH] fix bug 90583. r=mjudge/jfrancis sr=kin a=asa fix chinese ime candidate window position problem. we need the nsAutoPlaceHolderBatch destroctor called before hitting GetCaretCoordinates so the states in Frame system sync with content therefore, we put the nsAutoPlaceHolderBatch into a inner block { git-svn-id: svn://10.0.0.236/trunk@116055 18797224-902f-48f8-a5cc-f745e15eee43 --- .../editor/libeditor/html/nsHTMLEditor.cpp | 36 ++++++++++------ .../libeditor/text/nsPlaintextEditor.cpp | 43 +++++++++++-------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index bbec04cf143..e02117e995e 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -3722,25 +3722,35 @@ nsHTMLEditor::SetCompositionString(const nsAReadableString& aCompositionString, if (NS_FAILED(result)) return result; mIMETextRangeList = aTextRangeList; - nsAutoPlaceHolderBatch batch(this, gIMETxnName); - result = InsertText(aCompositionString); + // we need the nsAutoPlaceHolderBatch destructor called before hitting + // GetCaretCoordinates so the states in Frame system sync with content + // therefore, we put the nsAutoPlaceHolderBatch into a inner block + { + nsAutoPlaceHolderBatch batch(this, gIMETxnName); - mIMEBufferLength = aCompositionString.Length(); + result = InsertText(aCompositionString); - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - ps->GetCaret(getter_AddRefs(caretP)); - caretP->SetCaretDOMSelection(selection); + mIMEBufferLength = aCompositionString.Length(); + + if (!mPresShellWeak) + return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr ps = do_QueryReferent(mPresShellWeak); + if (!ps) + return NS_ERROR_NOT_INITIALIZED; + ps->GetCaret(getter_AddRefs(caretP)); + caretP->SetCaretDOMSelection(selection); + + // second part of 23558 fix: + if (aCompositionString.IsEmpty()) + { + mIMETextNode = nsnull; + } + } result = caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); + NS_ASSERTION(NS_SUCCEEDED(result), "cannot get caret position"); - // second part of 23558 fix: - if (aCompositionString.IsEmpty()) - { - mIMETextNode = nsnull; - } return result; } diff --git a/mozilla/editor/libeditor/text/nsPlaintextEditor.cpp b/mozilla/editor/libeditor/text/nsPlaintextEditor.cpp index d2170639d99..db9bf7ce268 100644 --- a/mozilla/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/mozilla/editor/libeditor/text/nsPlaintextEditor.cpp @@ -1906,26 +1906,35 @@ nsPlaintextEditor::SetCompositionString(const nsAReadableString& aCompositionStr if (NS_FAILED(result)) return result; mIMETextRangeList = aTextRangeList; - nsAutoPlaceHolderBatch batch(this, gIMETxnName); - result = InsertText(aCompositionString); - - mIMEBufferLength = aCompositionString.Length(); - - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - ps->GetCaret(getter_AddRefs(caretP)); - caretP->SetCaretDOMSelection(selection); - - caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, - &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); - - // second part of 23558 fix: - if (aCompositionString.IsEmpty()) + // we need the nsAutoPlaceHolderBatch destructor called before hitting + // GetCaretCoordinates so the states in Frame system sync with content + // therefore, we put the nsAutoPlaceHolderBatch into a inner block { - mIMETextNode = nsnull; + nsAutoPlaceHolderBatch batch(this, gIMETxnName); + + result = InsertText(aCompositionString); + + mIMEBufferLength = aCompositionString.Length(); + + if (!mPresShellWeak) + return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr ps = do_QueryReferent(mPresShellWeak); + if (!ps) + return NS_ERROR_NOT_INITIALIZED; + ps->GetCaret(getter_AddRefs(caretP)); + caretP->SetCaretDOMSelection(selection); + + // second part of 23558 fix: + if (aCompositionString.IsEmpty()) + { + mIMETextNode = nsnull; + } } + + result = caretP->GetCaretCoordinates(nsICaret::eIMECoordinates, selection, + &(aReply->mCursorPosition), &(aReply->mCursorIsCollapsed)); + NS_ASSERTION(NS_SUCCEEDED(result), "cannot get caret position"); return result; }