diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 42a5a973462d..5c4412528261 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -5136,6 +5136,7 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType) nsTextEditorState::SelectionProperties sp; if (GetEditorState()) { + mInputData.mState->SyncUpSelectionPropertiesBeforeDestruction(); sp = mInputData.mState->GetSelectionProperties(); } diff --git a/dom/html/nsTextEditorState.cpp b/dom/html/nsTextEditorState.cpp index 6976f00e4f4f..e4b63c8dbeab 100644 --- a/dom/html/nsTextEditorState.cpp +++ b/dom/html/nsTextEditorState.cpp @@ -1537,6 +1537,14 @@ nsTextEditorState::GetSelectionProperties() return mSelectionProperties; } +void +nsTextEditorState::SyncUpSelectionPropertiesBeforeDestruction() +{ + if (mBoundFrame) { + UnbindFromFrame(mBoundFrame); + } +} + void nsTextEditorState::SetSelectionProperties(nsTextEditorState::SelectionProperties& aProps) { diff --git a/dom/html/nsTextEditorState.h b/dom/html/nsTextEditorState.h index b07de4842e2e..33b541a402f4 100644 --- a/dom/html/nsTextEditorState.h +++ b/dom/html/nsTextEditorState.h @@ -261,6 +261,10 @@ public: void SetSelectionProperties(SelectionProperties& aProps); void WillInitEagerly() { mSelectionRestoreEagerInit = true; } bool HasNeverInitializedBefore() const { return !mEverInited; } + // Sync up our selection properties with our editor prior to being destroyed. + // This will invoke UnbindFromFrame() to ensure that we grab whatever + // selection state may be at the moment. + void SyncUpSelectionPropertiesBeforeDestruction(); // Get the selection range start and end points in our text. nsresult GetSelectionRange(int32_t* aSelectionStart, int32_t* aSelectionEnd);