include/svl/IndexedStyleSheets.hxx | 3 ++- include/svl/style.hxx | 2 +- svl/source/items/IndexedStyleSheets.cxx | 16 ++++++++++------ svl/source/items/style.cxx | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-)
New commits: commit 3999f5d12b2964d440a0a193cef76d889a9a0da7 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Jun 5 16:33:45 2024 +0100 Commit: Noel Grandin <[email protected]> CommitDate: Thu Jun 6 08:27:07 2024 +0200 Resolves: tdf#161430 reindex the correct style if there are duplicate names Change-Id: I6d4e96faef3ec6caa038edf7595f91f20d964807 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168436 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/include/svl/IndexedStyleSheets.hxx b/include/svl/IndexedStyleSheets.hxx index c58a4b736703..4904d5346a94 100644 --- a/include/svl/IndexedStyleSheets.hxx +++ b/include/svl/IndexedStyleSheets.hxx @@ -144,7 +144,8 @@ public: void Clear(StyleSheetDisposer& cleanup); void Reindex(); - void ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName); + void ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, + const OUString& rNewName); /** Warning: counting for n starts at 0, i.e., the 0th style sheet is the first that is found. */ SfxStyleSheetBase* GetNthStyleSheetThatMatchesPredicate(sal_Int32 n, diff --git a/include/svl/style.hxx b/include/svl/style.hxx index 87c5563ed547..eeab434dc45b 100644 --- a/include/svl/style.hxx +++ b/include/svl/style.hxx @@ -275,7 +275,7 @@ public: virtual SfxStyleSheetBase* Find( const OUString&, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All ); void Reindex(); - void ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName); + void ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName); /** Add a style sheet. * Not an actual public function. Do not call it from non-subclasses. */ diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx index 3761f0e427ef..90df6beb4fb4 100644 --- a/svl/source/items/IndexedStyleSheets.cxx +++ b/svl/source/items/IndexedStyleSheets.cxx @@ -83,14 +83,18 @@ sal_Int32 IndexedStyleSheets::GetNumberOfStyleSheets() const } void -IndexedStyleSheets::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName) +IndexedStyleSheets::ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName) { - auto it = mPositionsByName.find(rOldName); - if (it != mPositionsByName.end()) + std::pair<MapType::const_iterator, MapType::const_iterator> range = mPositionsByName.equal_range(rOldName); + for (MapType::const_iterator it = range.first; it != range.second; ++it) { - unsigned nPos = it->second; - mPositionsByName.erase(it); - mPositionsByName.insert(std::make_pair(rNewName, nPos)); + if (mStyleSheets[it->second].get() == &style) + { + unsigned nPos = it->second; + mPositionsByName.erase(it); + mPositionsByName.insert(std::make_pair(rNewName, nPos)); + break; + } } } diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index bfdbac6f3f93..916b1621b4f0 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -178,7 +178,7 @@ bool SfxStyleSheetBase::SetName(const OUString& rName, bool bReIndexNow) aFollow = rName; aName = rName; if (bReIndexNow) - m_pPool->ReindexOnNameChange(aOldName, rName); + m_pPool->ReindexOnNameChange(*this, aOldName, rName); m_pPool->Broadcast( SfxStyleSheetModifiedHint( aOldName, *this ) ); return true; @@ -891,9 +891,9 @@ SfxStyleSheetBasePool::Reindex() } void -SfxStyleSheetBasePool::ReindexOnNameChange(const OUString& rOldName, const OUString& rNewName) +SfxStyleSheetBasePool::ReindexOnNameChange(const SfxStyleSheetBase& style, const OUString& rOldName, const OUString& rNewName) { - pImpl->mxIndexedStyleSheets->ReindexOnNameChange(rOldName, rNewName); + pImpl->mxIndexedStyleSheets->ReindexOnNameChange(style, rOldName, rNewName); } const svl::IndexedStyleSheets&
