summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2023-01-18 08:54:02 -0900
committerJim Raykowski <raykowj@gmail.com>2023-01-26 03:12:48 +0000
commit60035ea9b46f10351ef0bd56d4999bc43558dd33 (patch)
tree4dcedc61c8e30443b04ba878c6e838f384759918
parent516bc904e94971b61e4b13af632bf321b0a4a640 (diff)
tdf#146178 Allow navigate by field to advance from last field
of document to the first field in the stack, and reverse Change-Id: Ie0ef1eee0c556644f0b87a65b4bde1a7d9cdf337 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145775 Tested-by: Jenkins Reviewed-by: Jim Raykowski <raykowj@gmail.com>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter6.cxx32
-rw-r--r--sw/source/uibase/uiview/viewmdi.cxx28
2 files changed, 59 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx
index a3cda9eca08f..5585723cb482 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -59,6 +59,8 @@
#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
#include <linguistic/misc.hxx>
+#include <workctrl.hxx>
+
using namespace osl;
using namespace com::sun::star;
using namespace com::sun::star::beans;
@@ -2400,6 +2402,36 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf151828)
CPPUNIT_ASSERT_EQUAL(OUString("MyTableName"), pFormat->GetName());
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf146178)
+{
+ createSwDoc();
+
+ SwDoc* pDoc = getSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
+
+ // insert two fields
+ dispatchCommand(mxComponent, ".uno:InsertTimeField", {});
+ dispatchCommand(mxComponent, ".uno:InsertDateField", {});
+
+ // navigate by field
+ SwView::SetMoveType(NID_FIELD);
+
+ // set cursor to the start of the document
+ pWrtShell->SttEndDoc(false);
+ // navigate to the previous field
+ dispatchCommand(mxComponent, ".uno:ScrollToPrevious", {});
+ // Before the fix the position would be 0, navigation did not wrap to end of document
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pCursor->GetPoint()->GetContentIndex());
+
+ // set cursor to the end of the document
+ pWrtShell->SttEndDoc(false);
+ // navigate to the next field
+ dispatchCommand(mxComponent, ".uno:ScrollToNext", {});
+ // Before the fix the position would be 1, navigation did not wrap to start of document
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pCursor->GetPoint()->GetContentIndex());
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/viewmdi.cxx b/sw/source/uibase/uiview/viewmdi.cxx
index f2c9ad63034a..cb070b655efc 100644
--- a/sw/source/uibase/uiview/viewmdi.cxx
+++ b/sw/source/uibase/uiview/viewmdi.cxx
@@ -428,8 +428,34 @@ IMPL_LINK( SwView, MoveNavigationHdl, void*, p, void )
FN_PREV_BOOKMARK);
break;
case NID_FIELD:
+ {
rSh.EnterStdMode();
- rSh.MoveFieldType(nullptr, bNext, SwFieldIds::Unknown);
+ rSh.StartAction();
+ SearchLabel eSearchLabel = SearchLabel::Empty;
+ if (!rSh.MoveFieldType(nullptr, bNext, SwFieldIds::Unknown))
+ {
+ // no field found in the move direction
+ // wrap and try again
+ SwShellCursor* pCursor = rSh.GetCursor_();
+ SwCursorSaveState aSaveState(*pCursor);
+ rSh.SttEndDoc(bNext);
+ // document might have a field at the start of the document
+ SwField* pField = rSh.GetCurField();
+ if ((bNext && pField && pField->GetTypeId() != SwFieldTypesEnum::Postit) ||
+ rSh.MoveFieldType(nullptr, bNext, SwFieldIds::Unknown))
+ {
+ eSearchLabel = bNext ? SearchLabel::EndWrapped : SearchLabel::StartWrapped;
+ }
+ else
+ {
+ // no visible fields found
+ pCursor->RestoreSavePos();
+ eSearchLabel = SearchLabel::NavElementNotFound;
+ }
+ }
+ SvxSearchDialogWrapper::SetSearchLabel(eSearchLabel);
+ rSh.EndAction();
+ }
break;
case NID_FIELD_BYTYPE:
{