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 622dcb18df01bbe6148ca388b2d1464989116ff8 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Jun 2 11:10:36 2025 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Mon Jun 2 11:45:52 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/+/186126 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> 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 df6c452a5308..5797ee966226 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) @@ -543,6 +550,31 @@ CPPUNIT_TEST_FIXTURE(Test, testBulletCharChangeOnIndent) // • and nBullet2 should be ◦. CPPUNIT_ASSERT(nBullet1 != nBullet2); } + +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 fafced1c9776..23f322fee156 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -481,7 +481,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));