diff options
author | László Németh <nemeth@numbertext.org> | 2021-11-08 12:04:39 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-11-09 20:13:58 +0100 |
commit | 83490dc97ca76c64a7d46839f4dbb8b1610f169f (patch) | |
tree | f4bb4a1eb001c23e38c13fd9602ca188c9e3ebee | |
parent | 87b74da15d2de7c6a8569ede8f2fc6abec7dbcb4 (diff) |
tdf#124904 sw: don't show deletions in referenced text
In fields, strikethrough/underline formatting of
track changes is not available. If the referenced
text of the fields contained partial deletions,
the field showed them as normal text, e.g. mixing up
the text of a heading with its removed typos.
Now these deleted parts are removed, except in the
following case: if the referenced text was completely
removed, show the whole deleted text in the reference
field, adding strikethrough to its tooltip text to help
the review process.
Note: this allows to handle both use cases, i.e. when
only a small part of a heading was modified (e.g. removing
typos), and 2) removing whole chapters with headings,
where the fields in the deleted text are more readable
with the text of the deleted headings, showing the
original text content.
See also commit daf2a7d957c829c551754871a3545495c0f76bc0
"tdf#61154 sw Table of Contents: remove tracked deletion".
Change-Id: I98bd8ded1591ae3c84957998e65f3cccac2a7884
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124843
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | sw/qa/extras/uiwriter/data/tdf124904.fodt | 40 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter3.cxx | 30 | ||||
-rw-r--r-- | sw/source/core/fields/reffld.cxx | 37 |
3 files changed, 103 insertions, 4 deletions
diff --git a/sw/qa/extras/uiwriter/data/tdf124904.fodt b/sw/qa/extras/uiwriter/data/tdf124904.fodt new file mode 100644 index 000000000000..0e98b49153a8 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf124904.fodt @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:officeooo="http://openoffice.org/2009/office" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text" xmlns:dc="http://purl.org/dc/elements/1.1/"> + <office:styles> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:default-style style:family="paragraph"> + <style:text-properties fo:language="en" fo:country="US"/> + </style:default-style> + </office:styles> + <office:body> + <office:text> + <text:tracked-changes text:track-changes="false"> + <text:changed-region xml:id="ct94000180659744" text:id="ct94000180659744"> + <text:insertion> + <office:change-info> + <dc:creator>x</dc:creator> + <dc:date>2021-11-08T11:45:09</dc:date> + </office:change-info> + </text:insertion> + </text:changed-region> + <text:changed-region xml:id="ct94000186222464" text:id="ct94000186222464"> + <text:deletion> + <office:change-info> + <dc:creator>x</dc:creator> + <dc:date>2021-11-08T11:39:40</dc:date> + </office:change-info> + </text:deletion> + </text:changed-region> + </text:tracked-changes> + <text:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + <text:sequence-decl text:display-outline-level="0" text:name="Figure"/> + </text:sequence-decls> + <text:h text:style-name="Heading_20_2" text:outline-level="2"><text:bookmark-start text:name="__RefHeading___Toc1_4053559556"/>Heading of example<text:change-start text:change-id="ct94000180659744"/> <text:span text:style-name="T1">document</text:span><text:change-end text:change-id="ct94000180659744"/> <text:change-start text:change-id="ct94000186222464"/>file<text:bookmark-end text:name="__RefHeading___Toc1_4053559556"/><text:change-end text:change-id="ct94000186222464"/></text:h> + <text:p text:style-name="P1">Reference to <text:bookmark-ref text:reference-format="number-all-superior" text:ref-name="__RefHeading___Toc1_4053559556"/><text:bookmark-ref text:reference-format="text" text:ref-name="__RefHeading___Toc1_4053559556">Heading of example document </text:bookmark-ref></text:p> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index cdd255f10343..72e91ba9f0cb 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -288,6 +288,36 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf61154) CPPUNIT_ASSERT_EQUAL(OUString("Text Inserted\t1"), pNext->GetText()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf124904) +{ + // don't show deletions in referenced text, + // (except if the full text is deleted) + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf124904.fodt"); + + // show changes + pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete + | RedlineFlags::ShowInsert); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE( + "redlines should be visible", + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // remove the first word "Heading" (with change tracking) to update the referenced text + dispatchCommand(mxComponent, ".uno:DelToEndOfWord", {}); + Scheduler::ProcessEventsToIdle(); + + // This was "Reference to Heading of document file" + CPPUNIT_ASSERT_EQUAL(OUString("Reference to of example document "), + getParagraph(2)->getString()); + + // don't hide the wholly deleted referenced text + dispatchCommand(mxComponent, ".uno:DelToEndOfLine", {}); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(OUString("Reference to Heading of example document file"), + getParagraph(2)->getString()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf100691) { SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf100691.fodt"); diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx index 330e5871c3ac..33552038ba40 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -398,14 +398,37 @@ const SwTextNode* SwGetRefField::GetReferencedTextNode() const return SwGetRefFieldType::FindAnchor( &pTyp->GetDoc(), m_sSetRefName, m_nSubType, m_nSeqNo, &nDummy ); } +// strikethrough for tooltips using Unicode combining character +static OUString lcl_formatStringByCombiningCharacter(const OUString& sText, const sal_Unicode cChar) +{ + OUStringBuffer sRet; + for (sal_Int32 i = 0; i < sText.getLength(); ++i) + { + sRet.append(sText[i]); + sRet.append(cChar); + } + return sRet.makeStringAndClear(); +} + // #i85090# OUString SwGetRefField::GetExpandedTextOfReferencedTextNode( SwRootFrame const& rLayout) const { const SwTextNode* pReferencedTextNode( GetReferencedTextNode() ); - return pReferencedTextNode - ? sw::GetExpandTextMerged(&rLayout, *pReferencedTextNode, true, false, ExpandMode(0)) - : OUString(); + if ( !pReferencedTextNode ) + return OUString(); + + // show the referenced text without the deletions, but if the whole text was + // deleted, show the original text for the sake of the comfortable reviewing, + // but with Unicode strikethrough in the tooltip + OUString sRet = sw::GetExpandTextMerged(&rLayout, *pReferencedTextNode, true, false, ExpandMode::HideDeletions); + if ( sRet.isEmpty() ) + { + static const sal_Unicode cStrikethrough = u'\x0336'; + sRet = sw::GetExpandTextMerged(&rLayout, *pReferencedTextNode, true, false, ExpandMode(0)); + sRet = lcl_formatStringByCombiningCharacter( sRet, cStrikethrough ); + } + return sRet; } void SwGetRefField::SetExpand( const OUString& rStr ) @@ -608,7 +631,13 @@ void SwGetRefField::UpdateField( const SwTextField* pFieldTextAttr ) if( nStart != nEnd ) // a section? { - m_sText = pTextNd->GetExpandText(pLayout, nStart, nEnd - nStart, false, false, false, ExpandMode(0)); + m_sText = pTextNd->GetExpandText(pLayout, nStart, nEnd - nStart, false, false, false, ExpandMode::HideDeletions); + // show the referenced text without the deletions, but if the whole text was + // deleted, show the original text for the sake of the comfortable reviewing + // (with strikethrough in tooltip, see GetExpandedTextOfReferencedTextNode()) + if ( m_sText.isEmpty() ) + m_sText = pTextNd->GetExpandText(pLayout, nStart, nEnd - nStart, false, false, false, ExpandMode(0)); + if (m_nSubType == REF_OUTLINE || (m_nSubType == REF_SEQUENCEFLD && REF_CONTENT == GetFormat())) { |