tdf#154864 Changing starting number of numbered list does nothing

regression from
    commit cd3c16fbcb4f8e5e4c4448bc7cda96e8476d6aec
    Author: Noel Grandin <noel.grandin@collabora.co.uk>
    Date:   Fri Oct 14 15:14:13 2022 +0200
    tdf#129101 CTRL+A & Cut very slow
    avoid repeated invalidation of number tree, shaves 90% time off

The problem is that, after the above change, InvalidateListTree is not
called late enough to force invalidation of all necessary stuff.

So simply delay that until we do re-validation in SwNumRule::Validate.

Change-Id: I796cc34fe7d66d4876ee06286a8af7029a759eca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160974
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/sw/qa/uitest/writer_tests7/tdf144439.py b/sw/qa/uitest/writer_tests7/tdf144439.py
index 34911ee..4d0ce46 100644
--- a/sw/qa/uitest/writer_tests7/tdf144439.py
+++ b/sw/qa/uitest/writer_tests7/tdf144439.py
@@ -40,6 +40,28 @@ class tdf144439(UITestCase):
            self.assertEqual(Para1.String, "List item")
            self.assertEqual(Para1.getPropertyValue("ListLabelString"), "1.1.")

            # this section is checking tdf#154864 - Changing starting number of numbered list does nothing
            #

            with self.ui_test.execute_dialog_through_command(".uno:BulletsAndNumberingDialog") as xDialog:
                # Select custom tab
                xTabs = xDialog.getChild("tabcontrol")
                select_pos(xTabs, "5")

                # Select numbering
                xNumFmt = xDialog.getChild("numfmtlb")
                select_by_text(xNumFmt, "1, 2, 3, ...")

                # Increase "start at"
                xStartAt = xDialog.getChild("startat")
                xStartAt.executeAction("UP", tuple())
                xStartAt.executeAction("UP", tuple())

            Paragraphs = document.Text.createEnumeration()
            Para1 = Paragraphs.nextElement()
            self.assertEqual(Para1.String, "List item")
            self.assertEqual(Para1.getPropertyValue("ListLabelString"), "1.3.")

    def test_tdf144439_outline(self):
        with self.ui_test.create_doc_in_start_center("writer") as document:
            xWriterDoc = self.xUITest.getTopFocusWindow()
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index d2cb989..9cef97d 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -153,10 +153,17 @@ void SwNumRule::RemoveTextNode( SwTextNode& rTextNode )
{
    tTextNodeList::iterator aIter =
        std::find( maTextNodeList.begin(), maTextNodeList.end(), &rTextNode );
    if ( aIter == maTextNodeList.end() )
        return;

    if ( aIter != maTextNodeList.end() )
    maTextNodeList.erase( aIter );

    // Just in case we remove a node after we have marked the rule invalid, but before we have validated the tree
    if (mbInvalidRuleFlag)
    {
        maTextNodeList.erase( aIter );
        SwList* pList = rTextNode.GetDoc().getIDocumentListsAccess().getListByName( rTextNode.GetListId() );
        if (pList)
            pList->InvalidateListTree();
    }
}

@@ -1051,23 +1058,6 @@ void SwNumRule::SetInvalidRule(bool bFlag)
    if (mbInvalidRuleFlag == bFlag)
        return;

    if (bFlag)
    {
        o3tl::sorted_vector< SwList* > aLists;
        for ( const SwTextNode* pTextNode : maTextNodeList )
        {
            // #i111681# - applying patch from cmc
            SwList* pList = pTextNode->GetDoc().getIDocumentListsAccess().getListByName( pTextNode->GetListId() );
            OSL_ENSURE( pList, "<SwNumRule::SetInvalidRule(..)> - list at which the text node is registered at does not exist. This is a serious issue.");
            if ( pList )
            {
                aLists.insert( pList );
            }
        }
        for ( auto aList : aLists )
            aList->InvalidateListTree();
    }

    mbInvalidRuleFlag = bFlag;
}

@@ -1168,8 +1158,13 @@ void SwNumRule::Validate(const SwDoc& rDoc)
    o3tl::sorted_vector< SwList* > aLists;
    for ( const SwTextNode* pTextNode : maTextNodeList )
    {
        aLists.insert( pTextNode->GetDoc().getIDocumentListsAccess().getListByName( pTextNode->GetListId() ) );
        SwList* pList = pTextNode->GetDoc().getIDocumentListsAccess().getListByName( pTextNode->GetListId() );
        aLists.insert( pList );
    }

    for ( auto aList : aLists )
        aList->InvalidateListTree();

    for ( auto aList : aLists )
        aList->ValidateListTree(rDoc);