tdf#154050 Unset external pointer before destroying

Regression of 48ca2336251d62ac2e90300cd9945fb84b1cddd8
("tdf#125040 Avoid flickering on context change").
Before that commit the state of toolbar commands was
updating async, which is how it managed to not crash.

Change-Id: I07e2ce25faf848c7db33dd029b54a98bafcf8fa9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148518
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
(cherry picked from commit 37b2bb1f6c18b915286264682bf0b3c25f0d552a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148501
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/sc/source/ui/drawfunc/futext3.cxx b/sc/source/ui/drawfunc/futext3.cxx
index 1c13bee..a0db578 100644
--- a/sc/source/ui/drawfunc/futext3.cxx
+++ b/sc/source/ui/drawfunc/futext3.cxx
@@ -92,6 +92,11 @@ void FuText::StopEditMode()
    if( pNote )
        rDoc.LockStreamValid(true);     // only the affected sheet is invalidated below

    /*  Unset the outliner undo manager before the call to SdrEndTextEdit.
        SdrObjEditView::SdrEndTextEdit destroys it, but then ScDrawView::SdrEndTextEdit
        initiates some UI update which might try to access the now invalid pointer. */
    rViewShell.SetDrawTextUndo( nullptr );

    /*  SdrObjEditView::SdrEndTextEdit() may try to delete the entire drawing
        object, if it does not contain text and has invisible border and fill.
        This must not happen for note caption objects. They will be removed
@@ -102,9 +107,6 @@ void FuText::StopEditMode()
        case. */
    /*SdrEndTextEditKind eResult =*/ pView->SdrEndTextEdit( pNote != nullptr );

    // or ScEndTextEdit (with drawview.hxx)
    rViewShell.SetDrawTextUndo( nullptr );

    vcl::Cursor* pCur = pWindow->GetCursor();
    if( pCur && pCur->IsVisible() )
        pCur->Hide();