diff --git a/dom/html/nsTextEditorState.cpp b/dom/html/nsTextEditorState.cpp index d9a7ba08b340..45752cafdd92 100644 --- a/dom/html/nsTextEditorState.cpp +++ b/dom/html/nsTextEditorState.cpp @@ -868,7 +868,7 @@ TextInputListener::OnSelectionChange(Selection& aSelection, mSelectionWasCollapsed = collapsed; - if (!weakFrame.IsAlive() || + if (!weakFrame.IsAlive() || !mFrame || !nsContentUtils::IsFocusedContent(mFrame->GetContent())) { return; } @@ -1712,8 +1712,9 @@ nsTextEditorState::SetSelectionRange(uint32_t aStart, uint32_t aEnd, props.SetEnd(aEnd); props.SetDirection(aDirection); } else { + WeakPtr self(this); aRv = mBoundFrame->SetSelectionRange(aStart, aEnd, aDirection); - if (aRv.Failed()) { + if (aRv.Failed() || !self.get()) { return; } rv = mBoundFrame->ScrollSelectionIntoView();