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 bf72417c53cbb564d7f28718b244ce94541f740c Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Sep 3 14:55:38 2020 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Sep 3 16:14:43 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. Change-Id: I260d3caab447c03a98655d8f5da310082ba0b46e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102003 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/inc/numrule.hxx b/sw/inc/numrule.hxx index dba69c701671..a4e986a9ae9c 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 b2c3ec7e7bdf..bd419d1f8b16 100644 --- a/sw/qa/core/doc/doc.cxx +++ b/sw/qa/core/doc/doc.cxx @@ -14,11 +14,15 @@ #include <svtools/embedhlp.hxx> #include <editeng/frmdiritem.hxx> #include <vcl/errinf.hxx> +#include <vcl/event.hxx> #include <wrtsh.hxx> #include <fmtanchr.hxx> #include <frameformats.hxx> #include <docsh.hxx> +#include <edtwin.hxx> +#include <view.hxx> +#include <ndtxt.hxx> char const DATA_DIRECTORY[] = "/sw/qa/core/doc/data/"; @@ -69,6 +73,24 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testTextboxTextRotateAngle) ErrorRegistry::Reset(); } +CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testNumDownIndent) +{ + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "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 43cbad07cb61..32afd8828b7a 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -54,6 +54,7 @@ #include <IDocumentState.hxx> #include <com/sun/star/beans/PropertyValue.hpp> +#include <wrtsh.hxx> using namespace ::com::sun::star; @@ -1438,6 +1439,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 b03419d744ba..279bf08127a6 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -2060,7 +2060,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() ) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits