Bug 1370806 - Part 2. Remove selection before calling nsIPlaintextEditor.setText. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Wed, 07 Jun 2017 15:31:06 +0900
changeset 413582 efb90e3387f03eeb114c0be8f59b8508e9ba2c3e
parent 413581 29687a739c34c4ef13532849c972232cdc7967df
child 413583 07a573e7aef39759c3a863c7ab4a974e50ebe1e0
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1370806
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);
         }