sw/inc/crsrsh.hxx                    |   11 ++++++-----
 sw/source/core/crsr/crstrvl.cxx      |   13 +++++++++++--
 sw/source/uibase/uiview/viewport.cxx |    8 +++-----
 3 files changed, 20 insertions(+), 12 deletions(-)

New commits:
commit 1e8ec03543a8404543b9226896d36ab6dc72fa8f
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jul 5 18:08:54 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Jul 7 14:36:47 2023 +0200

    tdf#155462: fix the scrollbar tooltip text
    
    Over the time when it was completely unused, it regressed in a couple
    of aspects:
    
    1. It got assembled in incorrect order: instead of appending chapter,
       it got prepended in commit 832e5aadbff006ec24959162c29756fe2b1982be
       (Related: fdo#38838 remove UniString::SearchAndReplaceAll, 2013-10-08);
    2. It started to show chapters, only when the respective heading are
       at the very top of screen, and show only page elsewhere, likely in
       commit 835cd06a047717dfe5e0f117959f3c042e13b21b (tdf#38093 Writer
       outline folding - outline visibility and on canvas ui, 2020-07-30),
       where a call to SwNode::FindOutlineNodeOfLevel was replaced with
       SwOutlineNodes::Seek_Entry in SwCursorShell::GetContentAtPos.
    
    Change-Id: I3f427f7ecb3b6c58a441220c555b22e765a533c4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154077
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 7e997097eb0e36bbb6f1eb8519acfc4e8eb6337a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154174

diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index cfba5cb852c1..233edb71c240 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -88,15 +88,16 @@ enum class IsAttrAtPos
     SmartTag         = 0x0800,
     FormControl      = 0x1000,
     TableRedline     = 0x2000,
-    TableColRedline  = 0x4000
+    TableColRedline  = 0x4000,
 #ifdef DBG_UTIL
-    ,CurrAttrs       = 0x8000        ///< only for debugging
-    ,TableBoxValue   = 0x10000       ///< only for debugging
+    CurrAttrs       = 0x8000,        ///< only for debugging
+    TableBoxValue   = 0x10000,       ///< only for debugging
 #endif
-    , ContentControl = 0x20000
+    ContentControl = 0x20000,
+    AllowContaining = 0x40000, // With Outline, finds an outline node for 
non-outline position
 };
 namespace o3tl {
-    template<> struct typed_flags<IsAttrAtPos> : is_typed_flags<IsAttrAtPos, 
0x3ffff> {};
+    template<> struct typed_flags<IsAttrAtPos> : is_typed_flags<IsAttrAtPos, 
0x7ffff> {};
 }
 
 struct SwContentAtPos
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index a1656233cfc9..d5e430bb8711 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -1466,8 +1466,17 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt,
         && !rNds.GetOutLineNds().empty() )
     {
         // only for nodes in outline nodes
-        SwOutlineNodes::size_type nPos;
-        if(rNds.GetOutLineNds().Seek_Entry(pTextNd, &nPos))
+        SwOutlineNodes::size_type nPos = 0;
+        bool bFoundOutline = rNds.GetOutLineNds().Seek_Entry(pTextNd, &nPos);
+        if (!bFoundOutline && nPos && (IsAttrAtPos::AllowContaining & 
rContentAtPos.eContentAtPos))
+        {
+            // nPos points to the first found outline node not before pTextNd, 
or to end();
+            // when bFoundOutline is false, and nPos is not 0, it means that 
there were
+            // outline nodes before pTextNd, and nPos-1 points to the last of 
those.
+            pTextNd = rNds.GetOutLineNds()[nPos - 1]->GetTextNode();
+            bFoundOutline = true;
+        }
+        if (bFoundOutline)
         {
             rContentAtPos.eContentAtPos = IsAttrAtPos::Outline;
             rContentAtPos.sStr = sw::GetExpandTextMerged(GetLayout(), 
*pTextNd, true, false, ExpandMode::ExpandFootnote);
diff --git a/sw/source/uibase/uiview/viewport.cxx 
b/sw/source/uibase/uiview/viewport.cxx
index 5446c708a5e9..7637852ed7d0 100644
--- a/sw/source/uibase/uiview/viewport.cxx
+++ b/sw/source/uibase/uiview/viewport.cxx
@@ -714,16 +714,14 @@ IMPL_LINK(SwView, VertScrollHdl, weld::Scrollbar&, 
rScrollbar, void)
                         aRect.SetBottom( aRect.Top() );
 
                         OUString sPageStr( GetPageStr( nPhNum, nVirtNum, 
sDisplay ));
-                        SwContentAtPos aCnt( IsAttrAtPos::Outline );
+                        SwContentAtPos aCnt(IsAttrAtPos::Outline | 
IsAttrAtPos::AllowContaining);
                         bool bSuccess = m_pWrtShell->GetContentAtPos(aPos, 
aCnt);
                         if (bSuccess && !aCnt.sStr.isEmpty())
                         {
-                            sPageStr += "  - ";
                             sal_Int32 nChunkLen = 
std::min<sal_Int32>(aCnt.sStr.getLength(), 80);
                             std::u16string_view sChunk = aCnt.sStr.subView(0, 
nChunkLen);
-                            sPageStr = sChunk + sPageStr;
-                            sPageStr = sPageStr.replace('\t', ' ');
-                            sPageStr = sPageStr.replace(0x0a, ' ');
+                            sPageStr = sPageStr + "  - " + sChunk;
+                            sPageStr = sPageStr.replace('\t', ' 
').replace(0x0a, ' ');
                         }
 
                         Help::ShowQuickHelp(m_pVScrollbar, aRect, sPageStr,

Reply via email to