sw/source/uibase/utlui/content.cxx |   50 ++++++++++++-------------------------
 1 file changed, 17 insertions(+), 33 deletions(-)

New commits:
commit 39155ca940cb1541c27a9db7f4a4bb17b935f4cc
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Tue Feb 8 22:58:58 2022 -0900
Commit:     Jim Raykowski <rayk...@gmail.com>
CommitDate: Fri Feb 11 07:08:27 2022 +0100

    SwNavigator: Improve bookmark tracking
    
    Change-Id: I217b46da48c662032d00e553639e985412f681ec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129710
    Tested-by: Jenkins
    Reviewed-by: Jim Raykowski <rayk...@gmail.com>

diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index b93c5a005132..ee88b6d3caa4 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -3527,43 +3527,27 @@ void SwContentTree::UpdateTracking()
             return;
         }
         // bookmarks - track first bookmark at cursor
-        if (m_pActiveShell->GetSelectionType() & SelectionType::Text)
+        if (m_bBookmarkTracking && (m_pActiveShell->GetSelectionType() & 
SelectionType::Text))
         {
-            SwDoc* pDoc = m_pActiveShell->GetDoc();
-            uno::Reference<text::XBookmarksSupplier> 
xBookmarksSupplier(pDoc->GetDocShell()->GetBaseModel(),
-                                                                        
uno::UNO_QUERY);
-            uno::Reference<container::XIndexAccess> 
xBookmarks(xBookmarksSupplier->getBookmarks(),
-                                                               uno::UNO_QUERY);
-            sal_Int32 nBookmarkCount = xBookmarks->getCount();
-            if (nBookmarkCount && !(m_bIsRoot && m_nRootType != 
ContentTypeId::BOOKMARK))
-            {
-                if (!m_bBookmarkTracking) return;
-                SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
-                uno::Reference<text::XTextRange> xRange(
-                            SwXTextRange::CreateXTextRange(*pDoc, 
*pCursor->GetPoint(), nullptr));
-                for (sal_Int32 i = 0; i < nBookmarkCount; ++i)
+            SwPaM* pCursor = m_pActiveShell->GetCursor();
+            IDocumentMarkAccess* const pMarkAccess = 
m_pActiveShell->getIDocumentMarkAccess();
+            IDocumentMarkAccess::const_iterator_t ppBookmark = 
pMarkAccess->getBookmarksBegin();
+            if (pCursor && ppBookmark != pMarkAccess->getBookmarksEnd() &&
+                    !(m_bIsRoot && m_nRootType != ContentTypeId::BOOKMARK))
+            {
+                SwPosition* pCursorPoint = pCursor->GetPoint();
+                while (ppBookmark != pMarkAccess->getBookmarksEnd())
                 {
-                    uno::Reference<text::XTextContent> bookmark;
-                    xBookmarks->getByIndex(i) >>= bookmark;
-                    try
-                    {
-                        uno::Reference<text::XTextRange> bookmarkRange = 
bookmark->getAnchor();
-                        uno::Reference<text::XTextRangeCompare> 
xTextRangeCompare(xRange->getText(),
-                                                                               
   uno::UNO_QUERY);
-                        if (xTextRangeCompare.is()
-                                && 
xTextRangeCompare->compareRegionStarts(bookmarkRange, xRange) != -1
-                                && 
xTextRangeCompare->compareRegionEnds(xRange, bookmarkRange) != -1)
-                        {
-                            uno::Reference<container::XNamed> 
xBookmark(bookmark, uno::UNO_QUERY);
-                            lcl_SelectByContentTypeAndName(this, *m_xTreeView,
-                                                           
SwResId(STR_CONTENT_TYPE_BOOKMARK),
-                                                           
xBookmark->getName());
-                            return;
-                        }
-                    }
-                    catch (const lang::IllegalArgumentException&)
+                    if (lcl_IsUiVisibleBookmark(*ppBookmark) &&
+                            *pCursorPoint >= (*ppBookmark)->GetMarkStart() &&
+                            *pCursorPoint <= (*ppBookmark)->GetMarkEnd())
                     {
+                        lcl_SelectByContentTypeAndName(this, *m_xTreeView,
+                                                       
SwResId(STR_CONTENT_TYPE_BOOKMARK),
+                                                       
(*ppBookmark)->GetName());
+                        return;
                     }
+                    ++ppBookmark;
                 }
             }
         }

Reply via email to