From 0a32def8b519461b35b1e249d71ae9961b04400a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 7 Feb 2024 14:52:05 +0200 Subject: [PATCH] tdf#158279 TOC links lost when converting .doc to HTML regression from commit 8ce36e943f0e50970925b2dd77729ef6036b4a49 Author: Noel Grandin Date: Sun May 26 15:15:41 2019 +0200 move some searching inside IDocumentMarkAccess where I called the wrong method from inside Writer::FindPos_Bkmk The code was then removed in commit 7bad1516c5f2a85b5bae3f49261ac2494cbb7162 Author: Noel Grandin Date: Wed Jul 17 05:41:08 2019 +0200 loplugin:unusedmethods Change-Id: I3f1e14a1e3ae2dd134738363e6b2679d2a2f418a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163095 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/inc/IDocumentMarkAccess.hxx | 7 +++++++ sw/source/core/doc/docbm.cxx | 10 ++++++++++ sw/source/core/inc/MarkManager.hxx | 1 + sw/source/filter/writer/writer.cxx | 6 +++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx index d63b58f606c4..bc8f2e1c03d6 100644 --- a/sw/inc/IDocumentMarkAccess.hxx +++ b/sw/inc/IDocumentMarkAccess.hxx @@ -279,6 +279,13 @@ class IDocumentMarkAccess */ virtual const_iterator_t findMark(const OUString& rMark) const =0; + /** Find the first Mark that does not start before. + + @returns + an iterator pointing to the mark, or pointing to getAllMarksEnd() if nothing was found. + */ + virtual const_iterator_t findFirstMarkNotStartsBefore(const SwPosition& rPos) const =0; + // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK ) /** check if the selection would delete a BOOKMARK */ diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 00681135b468..730da32625d4 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1410,6 +1410,16 @@ namespace sw::mark return IDocumentMarkAccess::iterator(ret); } + // find the first Mark that does not start before + IDocumentMarkAccess::const_iterator_t MarkManager::findFirstMarkNotStartsBefore(const SwPosition& rPos) const + { + return std::lower_bound( + m_vAllMarks.begin(), + m_vAllMarks.end(), + rPos, + CompareIMarkStartsBefore()); + } + IDocumentMarkAccess::const_iterator_t MarkManager::getAllMarksBegin() const { return m_vAllMarks.begin(); } diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx index ef0e79d74c11..dd7eb9f6f18b 100644 --- a/sw/source/core/inc/MarkManager.hxx +++ b/sw/source/core/inc/MarkManager.hxx @@ -81,6 +81,7 @@ namespace sw::mark { virtual const_iterator_t getAllMarksEnd() const override; virtual sal_Int32 getAllMarksCount() const override; virtual const_iterator_t findMark(const OUString& rName) const override; + virtual const_iterator_t findFirstMarkNotStartsBefore(const SwPosition& rPos) const override; // bookmarks virtual bool isBookmarkDeleted(SwPaM const& rPaM, bool isReplace) const override; diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx index a90482bfb31a..e21e81e5239c 100644 --- a/sw/source/filter/writer/writer.cxx +++ b/sw/source/filter/writer/writer.cxx @@ -157,9 +157,9 @@ bool Writer::CopyNextPam( SwPaM ** ppPam ) sal_Int32 Writer::FindPos_Bkmk(const SwPosition& rPos) const { const IDocumentMarkAccess* const pMarkAccess = m_pDoc->getIDocumentMarkAccess(); - const IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findFirstBookmarkStartsAfter(rPos); - if(ppBkmk != pMarkAccess->getBookmarksEnd()) - return ppBkmk - pMarkAccess->getBookmarksBegin(); + const IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findFirstMarkNotStartsBefore(rPos); + if(ppBkmk != pMarkAccess->getAllMarksEnd()) + return ppBkmk - pMarkAccess->getAllMarksBegin(); return -1; }