diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-01-12 16:57:48 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-01-13 07:13:39 +0000 |
commit | 04d50fa627faabb9211bd9fa9eb134599fb01982 (patch) | |
tree | 3be8aa1b62b87aa52ac0635345cb3fd5cc06aafd /sw/source | |
parent | 60be9811555b935d6860157ebf26fac6b48327ac (diff) |
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 <jluth@mail.com>
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 6 | ||||
-rw-r--r-- | sw/source/core/inc/MarkManager.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/uno/loktxdoc.cxx | 2 |
4 files changed, 8 insertions, 4 deletions
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) { |