sw/qa/uibase/shells/shells.cxx      |    9 +++++++--
 sw/source/uibase/shells/textsh1.cxx |    2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

New commits:
commit d2318503d559c3797965da777627e4ee45143043
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Jan 9 16:27:15 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 10 07:06:50 2023 +0000

    sw, UpdateBookmarks: support renaming bookmarks
    
    The problem was that the LOK API client wanted to change the name of the
    bookmark, but nothing happened, because we had a sanity check that made
    sure the provided vs existing bookmark names match.
    
    The intention was that the bookmark name is just an ID (you can store
    additional properties in per-doc custom properties, those can change),
    so we can require that bookmarks never get renamed when using this
    command.
    
    Fix the problem by dropping this requirement and rather use renameMark()
    to adjust the in-doc bookmark name if needed.
    
    This also handles undo/redo for us.
    
    Change-Id: I7a426c865ddf24f13741c0369fb3991da2e881b2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145235
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index a394221997cb..841a07993c98 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -467,7 +467,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
             {
                 "Bookmark": {
                     "type": "string",
-                    "value": "ZOTERO_BREF_GiQ7DAWQYWLy"
+                    "value": "ZOTERO_BREF_new1"
                 },
                 "BookmarkText": {
                     "type": "string",
@@ -477,7 +477,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
             {
                 "Bookmark": {
                     "type": "string",
-                    "value": "ZOTERO_BREF_PRxDGUb4SWXF"
+                    "value": "ZOTERO_BREF_new2"
                 },
                 "BookmarkText": {
                     "type": "string",
@@ -499,6 +499,11 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
     // - Actual  : ABCDE
     // i.e. the content was not updated.
     CPPUNIT_ASSERT_EQUAL(OUString("Anew result 1Cnew result 2E"), aActual);
+
+    // Without the accompanying fix in place, this test would have failed, 
ZOTERO_BREF_GiQ7DAWQYWLy
+    // was not renamed to ZOTERO_BREF_new1.
+    auto it = pDoc->getIDocumentMarkAccess()->findMark("ZOTERO_BREF_new1");
+    CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAllMarksEnd());
 }
 
 CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertFieldmarkReadonly)
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index f86621c78a56..400a9d39bce0 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -423,7 +423,7 @@ void UpdateBookmarks(SfxRequest& rReq, SwWrtShell& rWrtSh)
         comphelper::SequenceAsHashMap aMap(aBookmarks[nBookmarkIndex++]);
         if (aMap["Bookmark"].get<OUString>() != pMark->GetName())
         {
-            continue;
+            rIDMA.renameMark(pMark, aMap["Bookmark"].get<OUString>());
         }
 
         OUString aBookmarkText = aMap["BookmarkText"].get<OUString>();

Reply via email to