sw/source/core/text/porlay.cxx |    2 +-
 sw/source/core/text/txtfrm.cxx |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit 6f077add4f8c9ca909374dcd45c21d87eb3c0938
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Feb 20 20:06:57 2023 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Mar 2 09:12:18 2023 +0000

    tdf#114973 sw: don't allow every body SwTextFrame to be hidden
    
    Check this in SwTextFrame::IsHiddenNow() for the first one in the body.
    
    Also fix a bad entry in SwScriptInfo::m_HiddenChg that is then possible
    because it wasn't called on empty frames before.
    
    Change-Id: If57f8d1a30229cfbf97225b386365ae384c5083c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147347
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit b1814b7cc851c4346f6cfa81c5be74c46f42e90f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147440
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 7115c90e7bca..3b00fac71031 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -1272,7 +1272,7 @@ void SwScriptInfo::InitScriptInfo(const SwTextNode& rNode,
         {
             const Range& rRange = aHiddenMulti.GetRange( i );
             const sal_Int32 nStart = rRange.Min();
-            const sal_Int32 nEnd = rRange.Max() + 1;
+            const sal_Int32 nEnd = rRange.Max() + (rText.isEmpty() ? 0 : 1);
 
             m_HiddenChg.push_back( TextFrameIndex(nStart) );
             m_HiddenChg.push_back( TextFrameIndex(nEnd) );
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index aa371cd3df63..5906c9c9d1f3 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -1432,6 +1432,27 @@ bool SwTextFrame::IsHiddenNow() const
              ( bHiddenCharsHidePara &&
                !pVsh->GetViewOptions()->IsShowHiddenChar() ) )
         {
+            // in order to put the cursor in the body text, one paragraph must
+            // be visible - check this for the 1st body paragraph
+            if (IsInDocBody() && FindPrevCnt() == nullptr)
+            {
+                bool isAllHidden(true);
+                for (SwContentFrame const* pNext = FindNextCnt(true);
+                        pNext != nullptr; pNext = pNext->FindNextCnt(true))
+                {
+                    if (!pNext->IsTextFrame()
+                        || !static_cast<SwTextFrame 
const*>(pNext)->IsHiddenNow())
+                    {
+                        isAllHidden = false;
+                        break;
+                    }
+                }
+                if (isAllHidden)
+                {
+                    SAL_INFO("sw.core", "unhiding one body paragraph");
+                    return false;
+                }
+            }
             return true;
         }
     }

Reply via email to