tdf#160801 fix crash by delaying resetting of attributes

Calling SwWrtShell::ResetAttr() will sometimes delete the
current SwTextShell instance so call it after clearing the
direct formatting flag.

Change-Id: I43a66527cee30271447dff30f166086c6759e162
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168304
Tested-by: Jenkins
Reviewed-by: Patrick Luby <guibomacdev@gmail.com>
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index a51c7f6..0144b01 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1049,12 +1049,17 @@ void SwTextShell::Execute(SfxRequest &rReq)
                for (sal_uInt16 i = nBegin; i <= nEnd; ++i)
                    aAttribs.insert( i );
            }
            rWrtSh.ResetAttr( aAttribs );

            // also clear the direct formatting flag inside SwTableBox(es)
            if (SwFEShell* pFEShell = GetView().GetDocShell()->GetFEShell())
                pFEShell->UpdateTableStyleFormatting(nullptr, true);

            // tdf#160801 fix crash by delaying resetting of attributes
            // Calling SwWrtShell::ResetAttr() will sometimes delete the
            // current SwTextShell instance so call it after clearing the
            // direct formatting flag.
            rWrtSh.ResetAttr( aAttribs );

            rReq.Done();
            break;
        }