summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2023-05-02 20:05:41 -0400
committerMiklos Vajna <vmiklos@collabora.com>2023-05-03 14:18:42 +0200
commit92fe70072d16922af41ab0fd3746172f3a58e489 (patch)
tree6bfc6e2c4b7648e81a9513ace342f766f571de76
parent966e955ea09772ad1e3363f1813e5b26bfa41671 (diff)
tdf#148956 sw: clear nAttrStart == paraEnd hints in DOCX
I don't think that native Writer will create a character property at the end of a paragraph. (I couldn't do it manually or by round-tripping a problematic DOCX file.) However, DOCX does need to do this. However, a Ctrl-M to clear direct formatting was not clearing out those attributes (that don't span any text, but just sit at the end of the node). This patch fixes that problem. Change-Id: I6bd93fc145d226f785287e6991b7ea6e3fcd1c9b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151306 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/qa/extras/uiwriter/data/tdf148956_directEndFormatting.docxbin0 -> 6143 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx21
-rw-r--r--sw/source/core/txtnode/txtedt.cxx3
3 files changed, 23 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/data/tdf148956_directEndFormatting.docx b/sw/qa/extras/uiwriter/data/tdf148956_directEndFormatting.docx
new file mode 100644
index 000000000000..5c39c067231e
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf148956_directEndFormatting.docx
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 1833b1220dbd..9b40b3420c9e 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -85,6 +85,27 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf47471_paraStyleBackground)
getProperty<OUString>(getParagraph(3), "ParaStyleName"));
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf148956_directEndFormatting)
+{
+ createSwDoc("tdf148956_directEndFormatting.docx");
+ SwDoc* pDoc = getSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+ pWrtShell->EndPara(/*bSelect=*/true);
+ CPPUNIT_ASSERT_MESSAGE(
+ "Has direct formatting",
+ pWrtShell->GetCursor()->GetMark()->GetNode().GetTextNode()->GetpSwpHints());
+
+ dispatchCommand(mxComponent, ".uno:ResetAttributes", {});
+
+ dispatchCommand(mxComponent, ".uno:GotoStartOfPara", {});
+ dispatchCommand(mxComponent, ".uno:GotoEndOfPara", {});
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "Direct formatting cleared",
+ !pWrtShell->GetCursor()->GetMark()->GetNode().GetTextNode()->GetpSwpHints());
+}
+
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdfChangeNumberingListAutoFormat)
{
createSwDoc("tdf117923.docx");
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index d0da99a7986c..528afabed561 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -436,7 +436,8 @@ void SwTextNode::RstTextAttr(
SwTextAttr *pHt = nullptr;
while ( (i < m_pSwpHints->Count())
&& ( ( ( nAttrStart = m_pSwpHints->GetWithoutResorting(i)->GetStart()) < nEnd )
- || nLen==0 ) && !bExactRange)
+ || nLen==0 || (nEnd == nAttrStart && nAttrStart == m_Text.getLength()))
+ && !bExactRange)
{
pHt = m_pSwpHints->GetWithoutResorting(i);