Bug 1370806 - Part 2. Remove selection before calling nsIPlaintextEditor.setText. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 07 Jun 2017 15:31:06 +0900
changeset 590731 d2149a814760b5c6ae50d9f7a5c309fb837eb447
parent 590730 d0859fd2db6f92a948a51a8dc05a78c735f36fea
child 632288 5809d5ae5a322dc14845f70510952871989d12cb
push id62809
push userbmo:m_kato@ga2.so-net.ne.jp
push dateThu, 08 Jun 2017 01:13:10 +0000
reviewersmasayuki
bugs1370806
milestone55.0a1
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
dom/html/nsTextEditorState.cpp
--- 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);
         }