From ca66965507494d0c5e07bfe81334749bc08af409 Mon Sep 17 00:00:00 2001 From: Jim Raykowski Date: Sun, 14 Apr 2024 14:49:48 -0800 Subject: tdf#146190 Fix move to next drawing object using the tab key after double click on a drawing obect in the Navigator doesn't move to the next/previous drawing object when there is a number rule at the current current cursor position and the current cursor position is at the start of a paragraph. This patch reworks the SwWrtShell::GotoDrawingObject function so the document cursor position gets moved to the position of the drawing object when the object is selected. Another way to get expected results is to leave the GotoDrawingObject function as is and move: else if (rSh.GetSelectionType() & (SelectionType::Graphic | SelectionType::Frame | SelectionType::Ole | SelectionType::DrawObject | SelectionType::DbForm)) above the: else if( rSh.GetNumRuleAtCurrCursorPos() && rSh.IsSttOfPara() && !rSh.HasReadonlySel() ) in the SwEditWin::KeyInput function case KEY_TAB: block. SwWrtShell::GotoDrawingObject is made SW_DLLPUBIC by this patch to able to be used by the included unit test. Change-Id: I047b416ae94a9284d304798924e0c5f2be526f85 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166089 Tested-by: Jenkins Reviewed-by: Jim Raykowski --- sw/qa/extras/uiwriter/data/tdf146190.odt | Bin 0 -> 18070 bytes sw/qa/extras/uiwriter/uiwriter9.cxx | 38 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 sw/qa/extras/uiwriter/data/tdf146190.odt (limited to 'sw/qa/extras') diff --git a/sw/qa/extras/uiwriter/data/tdf146190.odt b/sw/qa/extras/uiwriter/data/tdf146190.odt new file mode 100644 index 000000000000..b686cb174bc9 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf146190.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx index f46d43e537b6..93d608a69247 100644 --- a/sw/qa/extras/uiwriter/uiwriter9.cxx +++ b/sw/qa/extras/uiwriter/uiwriter9.cxx @@ -47,6 +47,9 @@ #include #include +#include +#include + namespace { class SwUiWriterTest9 : public SwModelTestBase @@ -555,6 +558,41 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158375_ole_object_disable) comphelper::LibreOfficeKit::setActive(false); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf146190) +{ + // Given a document with a number rule at the start of a paragraph and two drawing objects: + createSwDoc("tdf146190.odt"); + SwXTextDocument* pXTextDocument = dynamic_cast(mxComponent.get()); + SwDocShell* pDocShell = pXTextDocument->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + + const SdrMarkList& rMrkList = pWrtShell->GetDrawView()->GetMarkedObjectList(); + + // Assert the current cursor position has a number rule and is at the start of a paragraph: + pWrtShell->SttEndDoc(/*bStt=*/true); + CPPUNIT_ASSERT(pWrtShell->GetNumRuleAtCurrCursorPos()); + CPPUNIT_ASSERT(pWrtShell->IsSttOfPara()); + + // Then go to "Shape 1" drawing object using the GotoDrawingObject function: + pWrtShell->GotoDrawingObject(u"Shape 1"); + CPPUNIT_ASSERT_EQUAL(OUString("Shape 1"), rMrkList.GetMark(0)->GetMarkedSdrObj()->GetName()); + + // Move to the next drawing object by Tab key press: + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); + Scheduler::ProcessEventsToIdle(); + // Without the fix in place, this test would have failed with: + // equality assertion failed + // - Expected: Shape 2 + // - Actual : Shape 1 + // i.e. Tab did not move to the next drawing object + CPPUNIT_ASSERT_EQUAL(OUString("Shape 2"), rMrkList.GetMark(0)->GetMarkedSdrObj()->GetName()); + + // Tab key press should now select 'Shape 1': + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_TAB); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(OUString("Shape 1"), rMrkList.GetMark(0)->GetMarkedSdrObj()->GetName()); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3