sw/inc/cmdid.h                      |    1 +
 sw/qa/uibase/shells/shells.cxx      |   27 +++++++++++++++++++++++++++
 sw/sdi/_textsh.sdi                  |    5 +++++
 sw/sdi/swriter.sdi                  |   14 ++++++++++++++
 sw/source/uibase/shells/textfld.cxx |    9 +++++++++
 5 files changed, 56 insertions(+)

New commits:
commit 243131397a5b626c2d8442dc716193e27b13ef9f
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Dec 8 16:43:28 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Dec 8 16:46:54 2022 +0000

    sw: introduce a .uno:GotoMark command
    
    This is meant to be used from macros, it does the same as manually
    opening the navigator, selecting a given bookmark and pressing enter.
    
    It also helps debugging when you want to jump somewhere, but the
    surrounding document content changes, so jumping to a certain page won't
    work due to the changing page number.
    
    Change-Id: I3bc08ae8023997bab89cf4732fb67233a6a1e134
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143825
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 838ccde78c83..cb21ddb5b441 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -106,6 +106,7 @@ class SwUINumRuleItem;
 
 #define FN_GOTO_NEXT_INPUTFLD   (FN_EDIT + 47)  /* go to next inputfield */
 #define FN_GOTO_PREV_INPUTFLD   (FN_EDIT + 48)  /* go to previous inputfield   
 */
+#define FN_GOTO_MARK            (FN_EDIT + 49)  /* go to bookmark by name */
 
 #define FN_REPEAT_SEARCH        (FN_EDIT + 50)  /* Search again */
 
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 1f89211e52e8..a9625ad9a59f 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -408,6 +408,33 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testInsertBookmark)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testGotoMark)
+{
+    // Given a document with 2 paragraphs, a bookmark on the second one:
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->SplitNode();
+    pWrtShell->SttEndDoc(/*bStt=*/false);
+    pWrtShell->SetBookmark(vcl::KeyCode(), "mybookmark");
+    SwNodeOffset nExpected = pWrtShell->GetCursor()->GetPointNode().GetIndex();
+
+    // When jumping to that mark from the doc start:
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+    uno::Sequence<css::beans::PropertyValue> aArgs = {
+        comphelper::makePropertyValue("GotoMark", 
uno::Any(OUString("mybookmark"))),
+    };
+    dispatchCommand(mxComponent, ".uno:GotoMark", aArgs);
+
+    // Then make sure that the final cursor position is at the bookmark:
+    SwNodeOffset nActual = pWrtShell->GetCursor()->GetPointNode().GetIndex();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 10 (bookmark)
+    // - Actual  : 9 (doc start)
+    // i.e. the actual jump didn't happen.
+    CPPUNIT_ASSERT_EQUAL(nExpected, nActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index 312462f5b474..98e32d3d58dc 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -971,6 +971,11 @@ interface BaseText
         ExecMethod = ExecField ;
         StateMethod = NoState ;
     ]
+    FN_GOTO_MARK // status(final|play)
+    [
+        ExecMethod = ExecField ;
+        StateMethod = NoState ;
+    ]
     FN_EXECUTE_MACROFIELD // status()
     [
         ExecMethod = ExecField ;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 84ca0997f982..2471dfcd9fb6 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -1730,6 +1730,20 @@ SfxVoidItem GotoNextInputField FN_GOTO_NEXT_INPUTFLD
     GroupId = SfxGroupId::Navigator;
 ]
 
+SfxVoidItem GotoMark FN_GOTO_MARK
+(SfxStringItem GotoMark FN_GOTO_MARK)
+[
+    AutoUpdate = FALSE,
+    FastCall = TRUE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    GroupId = SfxGroupId::Navigator;
+]
+
 SfxVoidItem GotoNextObject FN_GOTO_NEXT_OBJ
 ()
 [
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 80a955d2da16..1efdf57abed0 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -198,6 +198,15 @@ void SwTextShell::ExecField(SfxRequest &rReq)
             }
             break;
 
+        case FN_GOTO_MARK:
+        {
+            const SfxStringItem* pName = 
rReq.GetArg<SfxStringItem>(FN_GOTO_MARK);
+            if (pName)
+            {
+                rSh.GotoMark(pName->GetValue());
+            }
+        }
+        break;
         default:
             bMore = true;
     }

Reply via email to