diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index e4062bdb88..ff86543cde 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -11297,6 +11297,21 @@ bool wxRichTextAction::Do() CalculateRefreshOptimizations(optimizationLineCharPositions, optimizationLineYPositions); #endif + // Check if the current object focus needs to be changed before deletion of content + if (m_ctrl) + { + wxRichTextObject* c = m_ctrl->GetFocusObject(); + while (c) + { + if (c == container) + { + m_ctrl->StoreFocusObject(container); + break; + } + c = c->GetParent(); + } + } + container->DeleteRange(GetRange()); container->UpdateRanges(); // InvalidateHierarchy goes up the hierarchy as well as down, otherwise with a nested object, @@ -11455,6 +11470,21 @@ bool wxRichTextAction::Undo() CalculateRefreshOptimizations(optimizationLineCharPositions, optimizationLineYPositions); #endif + // Check if the current object focus needs to be changed before deletion of content + if (m_ctrl) + { + wxRichTextObject* c = m_ctrl->GetFocusObject(); + while (c) + { + if (c == container) + { + m_ctrl->StoreFocusObject(container); + break; + } + c = c->GetParent(); + } + } + container->DeleteRange(GetRange()); container->UpdateRanges();