From 09f3defad88415cf3874d6e35bc0232db6a98927 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 20 Oct 2013 17:19:32 +0000 Subject: [PATCH] Avoid crash when deleting range that includes the focus object. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/richtext/richtextbuffer.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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();