diff options
author | Jim Raykowski <raykowj@gmail.com> | 2022-02-08 22:58:58 -0900 |
---|---|---|
committer | Jim Raykowski <raykowj@gmail.com> | 2022-02-11 07:08:27 +0100 |
commit | 39155ca940cb1541c27a9db7f4a4bb17b935f4cc (patch) | |
tree | 48852687ace4b7174f6650ad30fa3fc92bd1500b /sw/source/uibase/utlui | |
parent | 473ffb6532b507aba9d69d0b57319f752142b0d2 (diff) |
SwNavigator: Improve bookmark tracking
Change-Id: I217b46da48c662032d00e553639e985412f681ec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129710
Tested-by: Jenkins
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
Diffstat (limited to 'sw/source/uibase/utlui')
-rw-r--r-- | sw/source/uibase/utlui/content.cxx | 50 |
1 files changed, 17 insertions, 33 deletions
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; } } } |