Resolves: tdf#137274 comment node not expandable when there are comments

if it was opened and closed before deleting (or undoing thereof) comments

If the node is currently not expanded, but it was previously expanded, then it
is not filled-on-demand because it is already filled.

If the content it tracks has changed, remove its current children and set it to
filled-on-demand if there would be a non-zero set of new children

Change-Id: Ic8eafea7f298d285d1e6c4a60cb21b57a971bd86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104061
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 56c39fa..626e535 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -2556,8 +2556,9 @@ bool SwContentTree::HasContentChanged()
                    // i.e. in header/footer
                    pArrType->FillMemberList(&bLevelOrVisibilityChanged);
                    bool bRemoveChildren = false;
                    const size_t nChildCount = GetChildCount(*xEntry);
                    if (nChildCount != pArrType->GetMemberCount())
                    const size_t nOldChildCount = GetChildCount(*xEntry);
                    const size_t nNewChildCount = pArrType->GetMemberCount();
                    if (nOldChildCount != nNewChildCount)
                    {
                        bRemoveChildren = true;
                    }
@@ -2565,7 +2566,7 @@ bool SwContentTree::HasContentChanged()
                    {
                        std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(xEntry.get()));
                        (void)m_xTreeView->iter_children(*xChild);
                        for (size_t j = 0; j < nChildCount; ++j)
                        for (size_t j = 0; j < nOldChildCount; ++j)
                        {
                            const SwContent* pCnt = pArrType->GetMember(j);
                            OUString sSubId(OUString::number(reinterpret_cast<sal_Int64>(pCnt)));
@@ -2585,8 +2586,8 @@ bool SwContentTree::HasContentChanged()
                            remove(*xRemove);
                            m_xTreeView->copy_iterator(*xEntry, *xRemove);
                        }
                        m_xTreeView->set_children_on_demand(*xEntry, nNewChildCount != 0);
                    }
                    m_xTreeView->set_children_on_demand(*xEntry, !nChildCount);
                }
                else if((nCntCount != 0)
                            != (pArrType->GetMemberCount()!=0))