[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-7-0' - sw/qa sw/source test/Package_unittest.mk test/user-template

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 23 13:52:41 UTC 2021


 sw/qa/extras/uiwriter/data/redline-autocorrect2.fodt |   24 +++++++++
 sw/qa/extras/uiwriter/uiwriter.cxx                   |   46 ++++++++++++++++++-
 sw/source/core/edit/acorrect.cxx                     |   17 ++++++-
 test/Package_unittest.mk                             |    1 
 test/user-template/user/autocorr/acor_en-GB.dat      |binary
 5 files changed, 84 insertions(+), 4 deletions(-)

New commits:
commit 892caa3fb770d00bdb8a10a0f298cdc5d487882a
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Fri Nov 6 19:14:45 2020 +0100
Commit:     Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Fri Apr 23 15:52:08 2021 +0200

    tdf#130546 sw autocorrect: don't replace redlining
    
    if it starts or ends within the removed text to
    avoid various problems, for example, reappearing
    deleted comma before ellipsis replacement:
    
    text[,]... -> text,...[,]
    
    or replacing words based on already deleted text:
    
    [tt]he -> [tt]the
    
    Add test/user-template/user/autocorr/acor_en-GB.dat
    unit test autocorrect definition with three dots to
    ellipsis replacement.
    
    Change-Id: I195922cb92bc29d3ded694fea4ca351244dab17b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105424
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111578
    Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>

diff --git a/sw/qa/extras/uiwriter/data/redline-autocorrect2.fodt b/sw/qa/extras/uiwriter/data/redline-autocorrect2.fodt
new file mode 100644
index 000000000000..4d65c5f465a2
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/redline-autocorrect2.fodt
@@ -0,0 +1,24 @@
+<?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="GB"/>
+  </style:default-style>
+ </office:styles>
+ <office:body>
+  <office:text>
+   <text:tracked-changes text:track-changes="false">
+    <text:changed-region xml:id="ct94099223789984" text:id="ct94099223789984">
+     <text:deletion>
+      <office:change-info>
+       <dc:creator>Unknown Author</dc:creator>
+       <dc:date>2020-11-03T19:19:05</dc:date>
+      </office:change-info>
+     </text:deletion>
+    </text:changed-region>
+   </text:tracked-changes>
+   <text:p text:style-name="P1">Lorem<text:change-start text:change-id="ct94099223789984"/>,<text:change-end text:change-id="ct94099223789984"/></text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 7b29b6026231..1d38cb951448 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -381,6 +381,7 @@ public:
     void testInconsistentBookmark();
     void testInsertLongDateFormat();
     void testRedlineAutoCorrect();
+    void testRedlineAutoCorrect2();
 #if HAVE_FEATURE_PDFIUM
     void testInsertPdf();
 #endif
@@ -605,6 +606,7 @@ public:
 #endif
     CPPUNIT_TEST(testInsertLongDateFormat);
     CPPUNIT_TEST(testRedlineAutoCorrect);
+    CPPUNIT_TEST(testRedlineAutoCorrect2);
 #if HAVE_FEATURE_PDFIUM
     CPPUNIT_TEST(testInsertPdf);
 #endif
@@ -7538,14 +7540,22 @@ void SwUiWriterTest::testRedlineAutoCorrect()
     pWrtShell->Insert("et");
     pWrtShell->AutoCorrect(corr, ' ');
     // This was "Ttest" removing the tracked deletion silently.
+    // Don't replace, if a redline starts or ends within the text.
     sReplaced = "tset ";
     nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
     CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
 
+    // Otherwise replace it
+    pWrtShell->Insert("tset");
+    pWrtShell->AutoCorrect(corr, ' ');
+    sReplaced = "tset test ";
+    nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+    CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
+
     // Including capitalization
     pWrtShell->Insert("end. word");
     pWrtShell->AutoCorrect(corr, ' ');
-    sReplaced = "tset end. Word ";
+    sReplaced = "tset test end. Word ";
     nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
     CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
 
@@ -7553,8 +7563,40 @@ void SwUiWriterTest::testRedlineAutoCorrect()
     dispatchCommand(mxComponent, ".uno:GoToStartOfDoc", {});
     pWrtShell->Insert("a");
     pWrtShell->AutoCorrect(corr, ' ');
-    sReplaced = "A tset end. Word ";
+    sReplaced = "A tset test end. Word ";
+    nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+    CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
+}
+
+void SwUiWriterTest::testRedlineAutoCorrect2()
+{
+    SwDoc* pDoc = createDoc("redline-autocorrect2.fodt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    dispatchCommand(mxComponent, ".uno:GoToEndOfDoc", {});
+
+    // show tracked deletion
+    RedlineFlags const nMode(pWrtShell->GetRedlineFlags() | RedlineFlags::On);
+    CPPUNIT_ASSERT(nMode & (RedlineFlags::ShowDelete | RedlineFlags::ShowInsert));
+    pWrtShell->SetRedlineFlags(nMode);
+    CPPUNIT_ASSERT(nMode & RedlineFlags::ShowDelete);
+
+    SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect());
+    pWrtShell->Insert("...");
+    pWrtShell->AutoCorrect(corr, ' ');
+    sal_uLong nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+
+    // This was "LoremLorem,…," (duplicating the deleted comma, but without deletion)
+    // Don't replace, if a redline starts or ends within the text.
+    OUString sReplaced = "Lorem,... ";
+    nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+    CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
+
+    // Continue it:
+    pWrtShell->Insert("Lorem,...");
+    pWrtShell->AutoCorrect(corr, ' ');
     nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+    sReplaced = u"Lorem,... Lorem,… ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
 }
 
diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx
index c872fde907cc..b09219d6a33f 100644
--- a/sw/source/core/edit/acorrect.cxx
+++ b/sw/source/core/edit/acorrect.cxx
@@ -409,9 +409,22 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
         SwPaM aPam(aStartPos, aEndPos);
 
         // don't replace, if a redline starts or ends within the original text
-        if ( pDoc->getIDocumentRedlineAccess().HasRedline( aPam, RedlineType::Any, /*bStartOrEndInRange=*/true ) )
+        for ( SwRedlineTable::size_type nAct =
+                  pDoc->getIDocumentRedlineAccess().GetRedlinePos( m_rCursor.GetNode(), RedlineType::Any );
+                  nAct < pDoc->getIDocumentRedlineAccess().GetRedlineTable().size(); ++nAct )
         {
-            return bRet;
+            const SwRangeRedline* pRed = pDoc->getIDocumentRedlineAccess().GetRedlineTable()[ nAct ];
+
+            if ( pRed->Start()->nNode > pTextNd->GetIndex() )
+                break;
+
+            // redline over the original text
+            if ( aStartPos < *pRed->End() && *pRed->Start() < aEndPos &&
+                 // starting or ending within the original text
+                 ( aStartPos < *pRed->Start() || *pRed->End() < aEndPos ) )
+            {
+                return bRet;
+            }
         }
 
         if( pFnd->IsTextOnly() )
diff --git a/test/Package_unittest.mk b/test/Package_unittest.mk
index 5973615edfed..2aabc9272eb4 100644
--- a/test/Package_unittest.mk
+++ b/test/Package_unittest.mk
@@ -24,6 +24,7 @@ $(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/sta
 $(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/crdbus50.bau,user/autotext/en-US/crdbus50.bau))
 $(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/.dummy,empty-directory-dummy))
 $(eval $(call gb_Package_add_file,test_unittest,unittest/user/autocorr/acor_en-US.dat,user/autocorr/acor_fr.dat))
+$(eval $(call gb_Package_add_file,test_unittest,unittest/user/autocorr/acor_en-GB.dat,user/autocorr/acor_en-GB.dat))
 $(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/scalc/popupmenu/draw.xml,user/config/soffice.cfg/modules/scalc/popupmenu/draw.xml))
 $(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/scalc/popupmenu/anchor.xml,user/config/soffice.cfg/modules/scalc/popupmenu/anchor.xml))
 $(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/modules/swriter/popupmenu/text.xml,user/config/soffice.cfg/modules/swriter/popupmenu/text.xml))
diff --git a/test/user-template/user/autocorr/acor_en-GB.dat b/test/user-template/user/autocorr/acor_en-GB.dat
new file mode 100644
index 000000000000..b74f1834caac
Binary files /dev/null and b/test/user-template/user/autocorr/acor_en-GB.dat differ


More information about the Libreoffice-commits mailing list