From e1017e8b129c8cc6f0debc4d24d5ad27e8b781c6 Mon Sep 17 00:00:00 2001 From: Makoto Kato Date: Wed, 7 Jun 2017 15:31:06 +0900 Subject: [PATCH] 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 --HG-- extra : rebase_source : 4df5d0629f083b75615b96b17bc108613fe80c24 --- dom/html/nsTextEditorState.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dom/html/nsTextEditorState.cpp b/dom/html/nsTextEditorState.cpp index 3ce9dc70ecb0..406e814da990 100644 --- a/dom/html/nsTextEditorState.cpp +++ b/dom/html/nsTextEditorState.cpp @@ -2661,6 +2661,11 @@ nsTextEditorState::SetValue(const nsAString& aValue, uint32_t aFlags) } } 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); }