[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sw/inc sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 3 14:46:19 UTC 2020


 sw/inc/numrule.hxx                       |    8 +++++
 sw/qa/core/doc/data/num-down-indent.docx |binary
 sw/qa/core/doc/doc.cxx                   |   22 +++++++++++++++
 sw/source/core/doc/number.cxx            |   45 +++++++++++++++++++++++++++++++
 sw/source/uibase/docvw/edtwin.cxx        |   11 ++++++-
 5 files changed, 85 insertions(+), 1 deletion(-)

New commits:
commit 535699c242da27efad59e7d666f50a507833968c
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Sep 3 14:55:38 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Sep 3 16:45:42 2020 +0200

    sw: insert plain tab char at a numbered para start if indent wouldn't change
    
    Pressing the <tab> key at the start of a numbered paragraph typically is
    not interpreted literally, rather we increase the numbering level by
    one. This results in a similar increase of indentation, and results in a
    semantically better document.
    
    However, this automagic is annoying in case the numbering is a leftover,
    which is not even visible, so the user only sees that pressing tab is
    "ignored" (if they don't pay attention to the status bar).
    
    Fix the problem by guessing if "downing" the numbering will change the
    indent, and if not, fall back to inserting a plain tab character
    instead, which will increase the indentation.
    
    Conflicts:
            sw/qa/core/doc/doc.cxx
    
    Change-Id: I260d3caab447c03a98655d8f5da310082ba0b46e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102004
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/inc/numrule.hxx b/sw/inc/numrule.hxx
index 6152e6bee99f..36bc1eaeac8f 100644
--- a/sw/inc/numrule.hxx
+++ b/sw/inc/numrule.hxx
@@ -43,6 +43,7 @@ class SwDoc;
 class SwFormatVertOrient;
 class SwTextNode;
 class Size;
+class SwWrtShell;
 
 const sal_Unicode cBulletChar = 0x2022; ///< Character for lists.
 
@@ -297,6 +298,13 @@ namespace numfunc
     */
     bool ChangeIndentOnTabAtFirstPosOfFirstListItem();
 
+    /**
+     * Decides if increasing ("downing") the numbering level will change the amount of indentation
+     * or not. This is typically true, unless the numbering levels are invisible and have no
+     * indents.
+     */
+    bool NumDownChangesIndent(SwWrtShell& rShell);
+
     SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode();
 }
 
diff --git a/sw/qa/core/doc/data/num-down-indent.docx b/sw/qa/core/doc/data/num-down-indent.docx
new file mode 100644
index 000000000000..86621c3cb9e7
Binary files /dev/null and b/sw/qa/core/doc/data/num-down-indent.docx differ
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index 72895861f713..80f338042281 100644
--- a/sw/qa/core/doc/doc.cxx
+++ b/sw/qa/core/doc/doc.cxx
@@ -15,9 +15,13 @@
 #include <svtools/embedhlp.hxx>
 #include <editeng/frmdiritem.hxx>
 #include <vcl/errinf.hxx>
+#include <vcl/event.hxx>
 
 #include <wrtsh.hxx>
 #include <fmtanchr.hxx>
+#include <edtwin.hxx>
+#include <view.hxx>
+#include <ndtxt.hxx>
 
 static char const DATA_DIRECTORY[] = "/sw/qa/core/doc/data/";
 
@@ -82,6 +86,24 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testTextboxTextRotateAngle)
     ErrorRegistry::Reset();
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testNumDownIndent)
+{
+    SwDoc* pDoc = createDoc("num-down-indent.docx");
+    SwDocShell* pDocShell = pDoc->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    pWrtShell->Down(/*bSelect=*/false);
+    SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
+    KeyEvent aKeyEvent(0, KEY_TAB);
+    rEditWin.KeyInput(aKeyEvent);
+    SwTextNode* pTextNode = pWrtShell->GetCursor()->GetNode().GetTextNode();
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: \tB
+    // - Actual  : B
+    // i.e. pressing <tab> at the start of the paragraph did not change the layout.
+    CPPUNIT_ASSERT_EQUAL(OUString("\tB"), pTextNode->GetText());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index c636273e6f54..37156ac40e83 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -53,6 +53,7 @@
 #include <IDocumentState.hxx>
 
 #include <com/sun/star/beans/PropertyValue.hpp>
+#include <wrtsh.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1425,6 +1426,50 @@ namespace numfunc
         return SwNumberingUIBehaviorConfig::getInstance().ChangeIndentOnTabAtFirstPosOfFirstListItem();
     }
 
+    bool NumDownChangesIndent(SwWrtShell& rShell)
+    {
+        SwPaM* pCursor = rShell.GetCursor();
+        if (!pCursor)
+        {
+            return true;
+        }
+
+        SwTextNode* pTextNode = pCursor->GetNode().GetTextNode();
+        if (!pTextNode)
+        {
+            return true;
+        }
+
+        const SwNumRule* pNumRule = pTextNode->GetNumRule();
+        if (!pNumRule)
+        {
+            return true;
+        }
+
+        int nOldLevel = pTextNode->GetActualListLevel();
+        int nNewLevel = nOldLevel + 1;
+        if (nNewLevel >= MAXLEVEL)
+        {
+            return true;
+        }
+
+        const SwNumFormat& rOldFormat = pNumRule->Get(nOldLevel);
+        if (rOldFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE)
+        {
+            return true;
+        }
+
+        const SwNumFormat& rNewFormat = pNumRule->Get(nNewLevel);
+        if (rNewFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE)
+        {
+            return true;
+        }
+
+        // This is the case when the numbering levels don't differ, so changing between them is not
+        // a better alternative to inserting a tab character.
+        return rOldFormat.GetIndentAt() != rNewFormat.GetIndentAt();
+    }
+
     SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode()
     {
         if (utl::ConfigManager::IsFuzzing())
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index d852df2d2182..e9d794eb2e0b 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -2027,7 +2027,16 @@ KEYINPUT_CHECKTABLE_INSDEL:
                              && numfunc::ChangeIndentOnTabAtFirstPosOfFirstListItem() )
                             eKeyState = SwKeyState::NumIndentInc;
                         else
-                            eKeyState = SwKeyState::NumDown;
+                        {
+                            if (numfunc::NumDownChangesIndent(rSh))
+                            {
+                                eKeyState = SwKeyState::NumDown;
+                            }
+                            else
+                            {
+                                eKeyState = SwKeyState::InsTab;
+                            }
+                        }
                     }
                     else if ( rSh.GetTableFormat() )
                     {


More information about the Libreoffice-commits mailing list