sc/qa/unit/tiledrendering/tiledrendering.cxx |    3 +
 sc/source/ui/inc/tabview.hxx                 |    6 ++-
 sc/source/ui/view/cellsh4.cxx                |    8 ++--
 sc/source/ui/view/tabview2.cxx               |   47 +++++++++++++++++++++++++--
 sc/source/ui/view/tabview3.cxx               |    4 +-
 5 files changed, 56 insertions(+), 12 deletions(-)

New commits:
commit 6568a29fa256d143a332b424c0582b0e665b65d6
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Jul 25 14:16:39 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Jul 26 09:54:03 2023 +0200

    cool#6931 on ctrl+[right/down] don't leap to the limits of the document
    
    ...when there is no more data, instead jump a generous block of emptiness.
    
    Limit to direct interaction by user and the simple navigation case
    (leaving block selection alone) and only for LibreOfficeKit::isActive
    
    Change-Id: I66234394529785d3f0f8fe6a6524239dad8ffb32
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154892
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index fd2413e9f0af..254fb5e8a042 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -1896,7 +1896,8 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testJumpToLastRowInvalidation)
     Scheduler::ProcessEventsToIdle();
     CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
     CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
-    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 13005, 26775, 267386880), 
aView1.m_aInvalidations[0]);
+    // 261375 because we limit how far we jump into empty space in online, 
267386880 if we don't limit
+    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 13005, 26775, 261375), 
aView1.m_aInvalidations[0]);
 }
 
 // We need to ensure that views are not perterbed by rendering (!?) hmm ...
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index 3f270770ec89..edb9dd991971 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -241,7 +241,8 @@ private:
     static tools::Long     GetScrollBarPos( const ScrollAdaptor& rScroll );
 
     void            GetAreaMoveEndPosition(SCCOL nMovX, SCROW nMovY, 
ScFollowMode eMode,
-                                           SCCOL& rAreaX, SCROW& rAreaY, 
ScFollowMode& rMode);
+                                           SCCOL& rAreaX, SCROW& rAreaY, 
ScFollowMode& rMode,
+                                           bool bInteractiveByUser = false);
 
     void            SkipCursorHorizontal(SCCOL& rCurX, SCROW& rCurY, SCCOL 
nOldX, SCCOL nMovX);
     void            SkipCursorVertical(SCCOL& rCurX, SCROW& rCurY, SCROW 
nOldY, SCROW nMovY);
@@ -435,7 +436,8 @@ public:
     void            MoveCursorPage( SCCOL nMovX, SCROW nMovY, ScFollowMode 
eMode,
                                     bool bShift, bool bKeepSel = false );
     void            MoveCursorArea( SCCOL nMovX, SCROW nMovY, ScFollowMode 
eMode,
-                                    bool bShift, bool bKeepSel = false );
+                                    bool bShift, bool bKeepSel = false,
+                                    bool bInteractiveByUser = false );
     void            MoveCursorEnd( SCCOL nMovX, SCROW nMovY, ScFollowMode 
eMode,
                                    bool bShift, bool bKeepSel = false );
     void            MoveCursorScreen( SCCOL nMovX, SCROW nMovY, ScFollowMode 
eMode, bool bShift );
diff --git a/sc/source/ui/view/cellsh4.cxx b/sc/source/ui/view/cellsh4.cxx
index e44dbe599dba..8cf13970bdeb 100644
--- a/sc/source/ui/view/cellsh4.cxx
+++ b/sc/source/ui/view/cellsh4.cxx
@@ -141,7 +141,7 @@ void ScCellShell::ExecuteCursor( SfxRequest& rReq )
             break;
 
         case SID_CURSORBLKDOWN:
-            pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, 
bKeep );
+            pTabViewShell->MoveCursorArea( 0, nRepeat, SC_FOLLOW_JUMP, bSel, 
bKeep, !rReq.IsAPI() );
             break;
 
         case SID_CURSORUP:
@@ -152,7 +152,7 @@ void ScCellShell::ExecuteCursor( SfxRequest& rReq )
             break;
 
         case SID_CURSORBLKUP:
-            pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, 
bKeep );
+            pTabViewShell->MoveCursorArea( 0, -nRepeat, SC_FOLLOW_JUMP, bSel, 
bKeep, !rReq.IsAPI() );
             break;
 
         case SID_CURSORLEFT:
@@ -163,7 +163,7 @@ void ScCellShell::ExecuteCursor( SfxRequest& rReq )
             break;
 
         case SID_CURSORBLKLEFT:
-            pTabViewShell->MoveCursorArea( static_cast<SCCOL>(-nRepeat * 
nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
+            pTabViewShell->MoveCursorArea( static_cast<SCCOL>(-nRepeat * 
nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep, !rReq.IsAPI() );
             break;
 
         case SID_CURSORRIGHT:
@@ -174,7 +174,7 @@ void ScCellShell::ExecuteCursor( SfxRequest& rReq )
             break;
 
         case SID_CURSORBLKRIGHT:
-            pTabViewShell->MoveCursorArea( static_cast<SCCOL>(nRepeat * 
nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep );
+            pTabViewShell->MoveCursorArea( static_cast<SCCOL>(nRepeat * 
nRTLSign), 0, SC_FOLLOW_JUMP, bSel, bKeep, !rReq.IsAPI() );
             break;
 
         case SID_CURSORPAGEDOWN:
diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx
index de7e0447b561..f80f0b309c15 100644
--- a/sc/source/ui/view/tabview2.cxx
+++ b/sc/source/ui/view/tabview2.cxx
@@ -37,6 +37,7 @@
 #include <globstr.hrc>
 #include <scresid.hxx>
 #include <scmod.hxx>
+#include <table.hxx>
 #include <tabprotection.hxx>
 #include <markdata.hxx>
 #include <inputopt.hxx>
@@ -697,7 +698,8 @@ void ScTabView::GetPageMoveEndPosition(SCCOL nMovX, SCROW 
nMovY, SCCOL& rPageX,
 }
 
 void ScTabView::GetAreaMoveEndPosition(SCCOL nMovX, SCROW nMovY, ScFollowMode 
eMode,
-                                       SCCOL& rAreaX, SCROW& rAreaY, 
ScFollowMode& rMode)
+                                       SCCOL& rAreaX, SCROW& rAreaY, 
ScFollowMode& rMode,
+                                       bool bInteractiveByUser)
 {
     SCCOL nNewX = -1;
     SCROW nNewY = -1;
@@ -706,6 +708,10 @@ void ScTabView::GetAreaMoveEndPosition(SCCOL nMovX, SCROW 
nMovY, ScFollowMode eM
     SCCOL nCurX = aViewData.GetCurX();
     SCROW nCurY = aViewData.GetCurY();
 
+    ScModule* pScModule = SC_MOD();
+    bool bLegacyCellSelection = 
pScModule->GetInputOptions().GetLegacyCellSelection();
+    bool bIncrementallyExpandToDocLimits(false);
+
     if (aViewData.IsRefMode())
     {
         nNewX = aViewData.GetRefEndX();
@@ -723,14 +729,17 @@ void ScTabView::GetAreaMoveEndPosition(SCCOL nMovX, SCROW 
nMovY, ScFollowMode eM
     {
         nNewX = nCurX;
         nNewY = nCurY;
+        // cool#6931 on ctrl+[right/down] don't immediately leap to the far 
limits of the document when no more data,
+        // instead jump a generous block of emptiness. Limit to direct 
interaction by user and the simple
+        // case.
+        bIncrementallyExpandToDocLimits = bInteractiveByUser && (nMovX == 1 || 
nMovY == 1) &&
+                                          !bLegacyCellSelection && 
comphelper::LibreOfficeKit::isActive();
     }
 
     ScDocument& rDoc = aViewData.GetDocument();
     SCTAB nTab = aViewData.GetTabNo();
 
     // FindAreaPos knows only -1 or 1 as direction
-    ScModule* pScModule = SC_MOD();
-    bool bLegacyCellSelection = 
pScModule->GetInputOptions().GetLegacyCellSelection();
     SCCOL nVirtualX = bLegacyCellSelection ? nNewX : nCurX;
     SCROW nVirtualY = bLegacyCellSelection ? nNewY : nCurY;
 
@@ -751,9 +760,41 @@ void ScTabView::GetAreaMoveEndPosition(SCCOL nMovX, SCROW 
nMovY, ScFollowMode eM
     if (eMode==SC_FOLLOW_JUMP)                  // bottom right do not show 
too much grey
     {
         if (nMovX != 0 && nNewX == rDoc.MaxCol())
+        {
             eMode = SC_FOLLOW_LINE;
+            if (bIncrementallyExpandToDocLimits)
+            {
+                if (const ScTable* pTab = rDoc.FetchTable(nTab))
+                {
+                    if (!pTab->HasData(nNewX, nCurY))
+                    {
+                        SCCOL nLastUsedCol(0);
+                        SCROW nLastUsedRow(0);
+                        rDoc.GetPrintArea(nTab, nLastUsedCol, nLastUsedRow);
+                        SCCOL nJumpFrom = std::max(nCurX, nLastUsedCol);
+                        nNewX = ((nJumpFrom / 13) + 2) * 13 - 1;
+                    }
+                }
+            }
+        }
         if (nMovY != 0 && nNewY == rDoc.MaxRow())
+        {
             eMode = SC_FOLLOW_LINE;
+            if (bIncrementallyExpandToDocLimits)
+            {
+                if (const ScTable* pTab = rDoc.FetchTable(nTab))
+                {
+                    if (!pTab->HasData(nCurX, nNewY))
+                    {
+                        SCCOL nLastUsedCol(0);
+                        SCROW nLastUsedRow(0);
+                        rDoc.GetPrintArea(nTab, nLastUsedCol, nLastUsedRow);
+                        SCROW nJumpFrom = std::max(nCurY, nLastUsedRow);
+                        nNewY = ((nJumpFrom / 500) + 2) * 500 - 1;
+                    }
+                }
+            }
+        }
     }
 
     if (aViewData.IsRefMode())
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index 74f6fc3753b6..bb0c4701387d 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -1331,11 +1331,11 @@ void ScTabView::MoveCursorPage( SCCOL nMovX, SCROW 
nMovY, ScFollowMode eMode, bo
     MoveCursorRel( nPageX, nPageY, eMode, bShift, bKeepSel );
 }
 
-void ScTabView::MoveCursorArea( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, 
bool bShift, bool bKeepSel )
+void ScTabView::MoveCursorArea( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, 
bool bShift, bool bKeepSel, bool bInteractiveByUser )
 {
     SCCOL nNewX;
     SCROW nNewY;
-    GetAreaMoveEndPosition(nMovX, nMovY, eMode, nNewX, nNewY, eMode);
+    GetAreaMoveEndPosition(nMovX, nMovY, eMode, nNewX, nNewY, eMode, 
bInteractiveByUser);
     MoveCursorRel(nNewX, nNewY, eMode, bShift, bKeepSel);
 }
 

Reply via email to