sw/qa/extras/uiwriter/data/tdf146190.odt |binary
 sw/qa/extras/uiwriter/uiwriter9.cxx      |   38 +++++++++++++++++++++++++++++++
 sw/source/uibase/inc/wrtsh.hxx           |    2 -
 sw/source/uibase/wrtsh/move.cxx          |   29 +++++++----------------
 4 files changed, 48 insertions(+), 21 deletions(-)

New commits:
commit ca66965507494d0c5e07bfe81334749bc08af409
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Sun Apr 14 14:49:48 2024 -0800
Commit:     Jim Raykowski <rayk...@gmail.com>
CommitDate: Sat Apr 20 18:14:00 2024 +0200

    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 <rayk...@gmail.com>

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 <fmtinfmt.hxx>
 #include <rootfrm.hxx>
 
+#include <svx/svdview.hxx>
+#include <svx/svdmark.hxx>
+
 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<SwXTextDocument*>(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();
 
diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index e1727bfc9fdf..6c0d4c2dda0b 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -501,7 +501,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)();
     SW_DLLPUBLIC bool GotoTable( const OUString& rName );
     void GotoFormatField( const SwFormatField& rField );
     const SwRangeRedline* GotoRedline( SwRedlineTable::size_type nArrPos, bool 
bSelect);
-    bool GotoDrawingObject(std::u16string_view rName);
+    SW_DLLPUBLIC bool GotoDrawingObject(std::u16string_view rName);
     void GotoFootnoteAnchor(const SwTextFootnote& rTextFootnote);
     SW_DLLPUBLIC void ChangeHeaderOrFooter(std::u16string_view rStyleName, 
bool bHeader, bool bOn, bool bShowWarning);
     virtual void SetShowHeaderFooterSeparator( FrameControlType eControl, bool 
bShow ) override;
diff --git a/sw/source/uibase/wrtsh/move.cxx b/sw/source/uibase/wrtsh/move.cxx
index cda2b32112ce..673a52091687 100644
--- a/sw/source/uibase/wrtsh/move.cxx
+++ b/sw/source/uibase/wrtsh/move.cxx
@@ -670,32 +670,21 @@ bool SwWrtShell::GotoOutline( const OUString& rName )
 bool SwWrtShell::GotoDrawingObject(std::u16string_view rName)
 {
     SwPosition aPos = *GetCursor()->GetPoint();
-    bool bRet = false;
-    SdrView* pDrawView = GetDrawView();
-    if (pDrawView)
+    SdrPage* pPage = getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+    for (const rtl::Reference<SdrObject>& pObj : *pPage)
     {
-        pDrawView->SdrEndTextEdit();
-        pDrawView->UnmarkAll();
-        SdrPage* pPage = 
getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
-        for (const rtl::Reference<SdrObject>& pObj : *pPage)
+        if (pObj->GetName() == rName)
         {
-            if (pObj->GetName() == rName)
+            bool bRet = SelectObj(Point(), 0, pObj.get());
+            if (bRet)
             {
-                SdrPageView* pPageView = pDrawView->GetSdrPageView();
-                if(pPageView)
-                {
-                    pDrawView->MarkObj(pObj.get(), pPageView);
-                    m_aNavigationMgr.addEntry(aPos);
-                    EnterStdMode();
-                    HideCursor();
-                    EnterSelFrameMode();
-                    bRet = true;
-                }
-                break;
+                m_aNavigationMgr.addEntry(aPos);
+                EnterSelFrameMode();
             }
+            return bRet;
         }
     }
-    return bRet;
+    return false;
 }
 
 bool SwWrtShell::GotoRegion( std::u16string_view rName )

Reply via email to