Bug 1310912 - Part 5. InsertTextIntoTextNodeImpl should use IMETextNode for listener. r?masayuki
When using CompositionTransaction, text node will be inserted into IMETextNode, not aTextNode of parameter. So we should use it for listener.
MozReview-Commit-ID: 72a3ZjF1wsz
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2433,17 +2433,18 @@ EditorBase::InsertTextImpl(const nsAStri
nsresult
EditorBase::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
Text& aTextNode,
int32_t aOffset,
bool aSuppressIME)
{
RefPtr<EditTransactionBase> transaction;
bool isIMETransaction = false;
- int32_t replacedOffset = 0;
+ RefPtr<Text> replacedTextNode = &aTextNode;
+ int32_t replacedOffset = aOffset;
// aSuppressIME is used when editor must insert text, yet this text is not
// part of the current IME operation. Example: adjusting whitespace around an
// IME insertion.
if (ShouldHandleIMEComposition() && !aSuppressIME) {
if (!mIMETextNode) {
mIMETextNode = &aTextNode;
mIMETextOffset = aOffset;
}
@@ -2463,40 +2464,41 @@ EditorBase::InsertTextIntoTextNodeImpl(c
textRange.mStartOffset, textRange.Length());
}
transaction = CreateTxnForComposition(aStringToInsert);
isIMETransaction = true;
// All characters of the composition string will be replaced with
// aStringToInsert. So, we need to emulate to remove the composition
// string.
+ replacedTextNode = mIMETextNode;
replacedOffset = mIMETextOffset;
mIMETextLength = aStringToInsert.Length();
} else {
transaction = CreateTxnForInsertText(aStringToInsert, aTextNode, aOffset);
}
// Let listeners know what's up
for (auto& listener : mActionListeners) {
listener->WillInsertText(
- static_cast<nsIDOMCharacterData*>(aTextNode.AsDOMNode()), aOffset,
- aStringToInsert);
+ static_cast<nsIDOMCharacterData*>(replacedTextNode->AsDOMNode()),
+ replacedOffset, aStringToInsert);
}
// XXX We may not need these view batches anymore. This is handled at a
// higher level now I believe.
BeginUpdateViewBatch();
nsresult rv = DoTransaction(transaction);
EndUpdateViewBatch();
// let listeners know what happened
for (auto& listener : mActionListeners) {
listener->DidInsertText(
- static_cast<nsIDOMCharacterData*>(aTextNode.AsDOMNode()),
- aOffset, aStringToInsert, rv);
+ static_cast<nsIDOMCharacterData*>(replacedTextNode->AsDOMNode()),
+ replacedOffset, aStringToInsert, rv);
}
// Added some cruft here for bug 43366. Layout was crashing because we left
// an empty text node lying around in the document. So I delete empty text
// nodes caused by IME. I have to mark the IME transaction as "fixed", which
// means that furure IME txns won't merge with it. This is because we don't
// want future IME txns trying to put their text into a node that is no
// longer in the document. This does not break undo/redo, because all these