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 9fa0b6977ba8292bfcc313caf080733090974c3f
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Jun 5 16:33:45 2024 +0100
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jun 6 08:26:42 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/+/168479
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/svl/IndexedStyleSheets.hxx 
b/include/svl/IndexedStyleSheets.hxx
index 685b958fa632..1934bc10af89 100644
--- a/include/svl/IndexedStyleSheets.hxx
+++ b/include/svl/IndexedStyleSheets.hxx
@@ -145,7 +145,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 018da0a04e67..522ef2437c60 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 adce9bf1dca2..0db2f201f35f 100644
--- a/svl/source/items/IndexedStyleSheets.cxx
+++ b/svl/source/items/IndexedStyleSheets.cxx
@@ -69,14 +69,18 @@ IndexedStyleSheets::Reindex()
 }
 
 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 a43e326ad877..3827b7cb0e7d 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;
@@ -890,9 +890,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&

Reply via email to