sw/qa/uibase/wrtsh/data/remove-indent.docx |binary sw/qa/uibase/wrtsh/wrtsh.cxx | 32 +++++++++++++++++++++++++++++ sw/source/uibase/inc/wrtsh.hxx | 2 - sw/source/uibase/wrtsh/delete.cxx | 2 - 4 files changed, 34 insertions(+), 2 deletions(-)
New commits: commit 66681fd117adc85ad827dcc018c522d6336e7f4b Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Jun 2 11:10:36 2025 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Jun 2 15:16:05 2025 +0200 tdf#166795 sw: fix removing indent of para with num rule which isn't counted Go to the end of the bugdoc, press backspace to make the paragraph not counted in the bullet list, then press backspace again. The cursor should move to the left, but it stays unchanged. This went wrong in commit db115bec9254417ef7a3faf687478fe5424ab378 (tdf#78510 sw,cui: split SvxLRSpaceItem for SwTextNode, SwTextFormatColl, 2023-02-24). The split of SvxLRSpaceItem to 3 separate pool items is great when it comes to modeling style inheritance correctly, but this broke reducing the indent on backspace in the bugdoc case. Fix the problem by extending the range of pool items we fetch at the cursor position in SwWrtShell::TryRemoveIndent(), once both the first line and the text left margin is fetched, this starts to work again. Note that Word turns off the numbering on the first backspace, while Writer makes the paragraph not counted instead -- this difference is not changed here. Change-Id: I9ac07a99befd59a54b566e61ff1c00277942b52e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186130 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186132 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/uibase/wrtsh/data/remove-indent.docx b/sw/qa/uibase/wrtsh/data/remove-indent.docx new file mode 100644 index 000000000000..f2a3c550ac8b Binary files /dev/null and b/sw/qa/uibase/wrtsh/data/remove-indent.docx differ diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx index 76449a0dd37d..20a8295de4e6 100644 --- a/sw/qa/uibase/wrtsh/wrtsh.cxx +++ b/sw/qa/uibase/wrtsh/wrtsh.cxx @@ -19,6 +19,7 @@ #include <sal/types.h> #include <comphelper/propertyvalue.hxx> #include <editeng/fontitem.hxx> +#include <editeng/lrspitem.hxx> #include <swmodeltestbase.hxx> #include <doc.hxx> @@ -31,12 +32,18 @@ #include <itabenum.hxx> #include <frmmgr.hxx> #include <formatflysplit.hxx> +#include <frmatr.hxx> namespace { /// Covers sw/source/uibase/wrtsh/ fixes. class Test : public SwModelTestBase { +public: + Test() + : SwModelTestBase(u"/sw/qa/uibase/wrtsh/data/"_ustr) + { + } }; CPPUNIT_TEST_FIXTURE(Test, testInsertLineBreak) @@ -506,6 +513,31 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlysAnchorJoin) pWrtShell->SttEndDoc(/*bStt=*/false); CPPUNIT_ASSERT_EQUAL(u"second para"_ustr, pCursor->GetPointNode().GetTextNode()->GetText()); } + +CPPUNIT_TEST_FIXTURE(Test, testRemoveIndent) +{ + // Given a document with an empty, bulleted paragraph at the document end: + createSwDoc("remove-indent.docx"); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + // Press backspace once to make it not numbered: + bool bOnlyBackspaceKey = true; + pWrtShell->NumOrNoNum(!bOnlyBackspaceKey); + + // When pressing backspace again to try to decrease its indent to change from left margin to + // first line margin: + pWrtShell->TryRemoveIndent(); + + // Then make sure we we actually decrease the indent: + SwPaM* pCursor = pWrtShell->GetCursor(); + SwTextNode* pTextNode = pCursor->GetPointNode().GetTextNode(); + SwTwips nLeftMargin = pTextNode->GetSwAttrSet().GetTextLeftMargin().GetTextLeft().m_dValue; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1135 + // - Actual : 1418 + // i.e. there was no decrease of the left text margin on pressing backspace. + CPPUNIT_ASSERT_EQUAL(static_cast<SwTwips>(1135), nLeftMargin); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index c0a2a8148081..3534e439dd6a 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -480,7 +480,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)(); const SwViewOption *pViewOpt); virtual ~SwWrtShell() override; - bool TryRemoveIndent(); // #i23725# + SW_DLLPUBLIC bool TryRemoveIndent(); // #i23725# OUString GetSelDescr() const; diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 16e3406d585a..8d0d4f3c7c1f 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -65,7 +65,7 @@ bool SwWrtShell::TryRemoveIndent() { bool bResult = false; - SfxItemSetFixed<RES_MARGIN_FIRSTLINE, RES_MARGIN_FIRSTLINE> aAttrSet(GetAttrPool()); + SfxItemSetFixed<RES_MARGIN_FIRSTLINE, RES_MARGIN_TEXTLEFT> aAttrSet(GetAttrPool()); GetCurAttr(aAttrSet); SvxFirstLineIndentItem firstLine(aAttrSet.Get(RES_MARGIN_FIRSTLINE));