sw/inc/IDocumentMarkAccess.hxx | 2 +- sw/source/core/doc/docbm.cxx | 6 +++++- sw/source/core/inc/MarkManager.hxx | 2 +- sw/source/uibase/shells/textsh1.cxx | 2 +- sw/source/uibase/uno/loktxdoc.cxx | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-)
New commits: commit 04d50fa627faabb9211bd9fa9eb134599fb01982 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jan 12 16:57:48 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Jan 13 07:13:39 2023 +0000 sw: rename getBookmarkFor() to getInnerBookmarkFor() Because otherwise it's quite confusing that we have a For() and an At() variant as well, and it would be less clear what happens in For() when there are multiple matches. Also improve getInnerBookmarkFor() a tiny little, so we process the first hit only once. Suggested at <https://gerrit.libreoffice.org/c/core/+/145348/1#message-286262286f234823b390e8f962e3ba11f5fa71b2>. Change-Id: If068f93e6934c9fc042760c03aac866fe5b50bd2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145412 Reviewed-by: Justin Luth <jl...@mail.com> Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index 20f876d16495..f07a6b6e1fe7 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -314,7 +314,7 @@ class IDocumentMarkAccess virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const =0; /// Get the innermost bookmark that contains rPos. - virtual sw::mark::IMark* getBookmarkFor(const SwPosition& rPos) const = 0; + virtual sw::mark::IMark* getInnerBookmarkFor(const SwPosition& rPos) const = 0; // Fieldmarks /** returns a STL-like random access iterator to the begin of the sequence of fieldmarks. diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 7152c2a2314a..468b5a2e3b11 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1437,7 +1437,7 @@ namespace sw::mark return dynamic_cast<IFieldmark*>(pFieldmark); } - IMark* MarkManager::getBookmarkFor(const SwPosition& rPos) const + IMark* MarkManager::getInnerBookmarkFor(const SwPosition& rPos) const { auto it = std::find_if(m_vBookmarks.begin(), m_vBookmarks.end(), [&rPos](const sw::mark::MarkBase* pMark) @@ -1447,6 +1447,10 @@ namespace sw::mark return nullptr; } sw::mark::IMark* pBookmark = *it; + + // See if any bookmarks after the first hit are closer to rPos. + ++it; + for (; it != m_vBookmarks.end() && (*it)->GetMarkStart() <= rPos; ++it) { // Find the innermost bookmark. diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index 1599996ae055..0b3f6d7df37d 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -88,7 +88,7 @@ namespace sw::mark { virtual sal_Int32 getBookmarksCount() const override; virtual const_iterator_t findBookmark(const OUString& rName) const override; virtual const_iterator_t findFirstBookmarkStartsAfter(const SwPosition& rPos) const override; - virtual ::sw::mark::IMark* getBookmarkFor(const SwPosition& rPos) const override; + virtual ::sw::mark::IMark* getInnerBookmarkFor(const SwPosition& rPos) const override; // Fieldmarks virtual const_iterator_t getFieldmarksBegin() const override; diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 7e8edb2fc508..bb5acfc9f47d 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -569,7 +569,7 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh) IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess(); SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint(); - auto pBookmark = dynamic_cast<sw::mark::Bookmark*>(rIDMA.getBookmarkFor(rCursor)); + auto pBookmark = dynamic_cast<sw::mark::Bookmark*>(rIDMA.getInnerBookmarkFor(rCursor)); if (!pBookmark || !pBookmark->GetName().startsWith(aBookmarkNamePrefix)) { return; diff --git a/sw/source/uibase/uno/loktxdoc.cxx b/sw/source/uibase/uno/loktxdoc.cxx index 6742c819c899..875384d1f307 100644 --- a/sw/source/uibase/uno/loktxdoc.cxx +++ b/sw/source/uibase/uno/loktxdoc.cxx @@ -250,7 +250,7 @@ void GetBookmark(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell, IDocumentMarkAccess& rIDMA = *pDocShell->GetDoc()->getIDocumentMarkAccess(); SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint(); - sw::mark::IMark* pBookmark = rIDMA.getBookmarkFor(rCursor); + sw::mark::IMark* pBookmark = rIDMA.getInnerBookmarkFor(rCursor); tools::ScopedJsonWriterNode aBookmark = rJsonWriter.startNode("bookmark"); if (!pBookmark) {