Bug 1370806 - Part 2. Remove selection before calling nsIPlaintextEditor.setText. r?masayuki
nsIPlaintestEditor.setText still use BeginPlaceHolderTransaction and EndPlaceHolderTransaction. But since input.value setter doesn't create undo transaction, it is unnecessary to save/restore selection via AutoPlaceHolderBatch. So before calling setText, we should reset selection to reduce saving and restoring selection.
Save/Restore selection is ~7% of input.value setter.
MozReview-Commit-ID: 6yBKCtRmkQt
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -2656,16 +2656,21 @@ nsTextEditorState::SetValue(const nsAStr
if (insertValue.IsEmpty()) {
mEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
} else {
plaintextEditor->InsertText(insertValue);
}
} else {
AutoDisableUndo disableUndo(mEditor);
+ if (domSel) {
+ // Since we don't use undo transaction, we don't need to store
+ // selection state. SetText will set selection to tail.
+ domSel->RemoveAllRanges();
+ }
plaintextEditor->SetText(newValue);
}
mTextListener->SetValueChanged(true);
mTextListener->SettingValue(false);
}