[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Mon Nov 9 14:59:40 UTC 2020


 sw/inc/IDocumentRedlineAccess.hxx             |    5 ++
 sw/qa/extras/uiwriter/uiwriter.cxx            |    9 ++++-
 sw/source/core/doc/DocumentRedlineManager.cxx |   29 ++++++++++++++++
 sw/source/core/edit/acorrect.cxx              |   45 +++-----------------------
 sw/source/core/inc/DocumentRedlineManager.hxx |    5 ++
 5 files changed, 53 insertions(+), 40 deletions(-)

New commits:
commit 2951c96bcb673a260a09e2c6eb92ca0f99bf0c18
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Mon Nov 9 11:36:57 2020 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Mon Nov 9 15:59:00 2020 +0100

    tdf#83419 sw change tracking: clean-up autocorrect
    
    fix of commit ac84cf7dda4a5150ff23e112ee16f00b8de8ec7c
    (tdf#83419 sw change tracking: fix bad autocorrect).
    
    Now automatic sentence capitalization and
    correction of two initial capitals are allowed
    again, if there is a tracked deletion in the same
    paragraph before the modified word.
    
    Change-Id: I8c583df2f14468b47079019009e7937f559b652b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105477
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/inc/IDocumentRedlineAccess.hxx b/sw/inc/IDocumentRedlineAccess.hxx
index 395fae8d47e2..0e4c9e33fb52 100644
--- a/sw/inc/IDocumentRedlineAccess.hxx
+++ b/sw/inc/IDocumentRedlineAccess.hxx
@@ -170,6 +170,11 @@ public:
         /*[in]*/const SwNode& rNode,
         /*[in]*/RedlineType nType) const = 0;
 
+    virtual bool HasRedline(
+        /*[in]*/const SwPaM& rPam,
+        /*[in]*/RedlineType nType,
+        /*[in]*/bool bStartOrEndInRange) const = 0;
+
     virtual void CompressRedlines() = 0;
 
     virtual const SwRangeRedline* GetRedline(
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 2acfc17b7082..f1bb78af34cb 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -7652,11 +7652,18 @@ void SwUiWriterTest::testRedlineAutoCorrect()
     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 test end. Word ";
+    nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+    CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
+
     // tracked deletions after the correction point doesn't affect autocorrect
     dispatchCommand(mxComponent, ".uno:GoToStartOfDoc", {});
     pWrtShell->Insert("a");
     pWrtShell->AutoCorrect(corr, ' ');
-    sReplaced = "A tset test ";
+    sReplaced = "A tset test end. Word ";
     nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
     CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText());
 }
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx
index 22893963b5b1..17419eda39ba 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -2523,6 +2523,35 @@ SwRedlineTable::size_type DocumentRedlineManager::GetRedlinePos( const SwNode& r
     // #TODO - add 'SwExtraRedlineTable' also ?
 }
 
+bool DocumentRedlineManager::HasRedline( const SwPaM& rPam, RedlineType nType, bool bStartOrEndInRange ) const // xxx
+{
+    SwPosition currentStart(*rPam.Start());
+    SwPosition currentEnd(*rPam.End());
+    SwNodeIndex pEndNodeIndex(currentEnd.nNode.GetNode());
+
+    for( SwRedlineTable::size_type n = GetRedlinePos( rPam.Start()->nNode.GetNode(), nType );
+                    n < mpRedlineTable->size(); ++n )
+    {
+        const SwRangeRedline* pTmp = (*mpRedlineTable)[ n ];
+
+        if ( pTmp->Start()->nNode > pEndNodeIndex )
+            break;
+
+        if( RedlineType::Any != nType && nType != pTmp->GetType() )
+            continue;
+
+        // redline over the range
+        if ( currentStart < *pTmp->End() && *pTmp->Start() <= currentEnd &&
+             // starting or ending within the range
+             ( !bStartOrEndInRange ||
+                 ( currentStart <= *pTmp->Start() || *pTmp->End() <= currentEnd ) ) )
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 const SwRangeRedline* DocumentRedlineManager::GetRedline( const SwPosition& rPos,
                                     SwRedlineTable::size_type* pFndPos ) const
 {
diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx
index d7003ccfbaed..a1c06e0442d1 100644
--- a/sw/source/core/edit/acorrect.cxx
+++ b/sw/source/core/edit/acorrect.cxx
@@ -42,6 +42,7 @@
 #include <editeng/acorrcfg.hxx>
 #include <redline.hxx>
 #include <IDocumentRedlineAccess.hxx>
+#include <rootfrm.hxx>
 
 using namespace ::com::sun::star;
 
@@ -231,31 +232,10 @@ bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const
     // tdf#83419 avoid bad autocorrect with visible redlines
     // e.g. replacing the first letter of the tracked deletion
     // with its capitalized (and not deleted) version.
-    if ( bDoReplace )
+    if ( bDoReplace && !pFrame->getRootFrame()->IsHideRedlines() &&
+         m_rEditSh.GetDoc()->getIDocumentRedlineAccess().HasRedline( *pPam, RedlineType::Delete, /*bStartOrEndInRange=*/false ) )
     {
-        const OUString& rOrigText = pos.first->GetText();
-        // GetRedlineText() doesn't contain dummy characters, so handle them
-        sal_Int32 nLengthCorrection = 0;
-        for (sal_Int32 n = 0; n < rOrigText.getLength(); ++n)
-        {
-            sal_Unicode const Char = rOrigText[n];
-            if ( CH_TXTATR_BREAKWORD == Char || CH_TXTATR_INWORD == Char )
-                ++nLengthCorrection;
-        }
-        sal_Int32 nDelChars = rOrigText.getLength() - nLengthCorrection -
-                              pos.first->GetRedlineText().getLength();
-        // Are there tracked deletions before the correction point?
-        if ( nDelChars > 0 && pos.first->GetRedlineText().compareTo( nLengthCorrection == 0
-                                  ? rOrigText
-                                  : rOrigText.replaceAll(OUString(CH_TXTATR_INWORD), "")
-                                         .replaceAll(OUString(CH_TXTATR_BREAKWORD), ""),
-                              pos.second + nSourceLength + nDelChars ) != 0 &&
-            // and are they visible?
-            pFrame->GetText().compareTo(
-                    rOrigText, pos.second + nSourceLength + nDelChars + nLengthCorrection) == 0 )
-        {
-            bDoReplace = false;
-        }
+        bDoReplace = false;
     }
 
     if ( bDoReplace )
@@ -434,22 +414,9 @@ 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
-        for ( SwRedlineTable::size_type nAct =
-                  pDoc->getIDocumentRedlineAccess().GetRedlinePos( m_rCursor.GetNode(), RedlineType::Any );
-                  nAct < pDoc->getIDocumentRedlineAccess().GetRedlineTable().size(); ++nAct )
+        if ( pDoc->getIDocumentRedlineAccess().HasRedline( aPam, RedlineType::Any, /*bStartOrEndInRange=*/true ) )
         {
-            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;
-            }
+            return bRet;
         }
 
         if( pFnd->IsTextOnly() )
diff --git a/sw/source/core/inc/DocumentRedlineManager.hxx b/sw/source/core/inc/DocumentRedlineManager.hxx
index a9811827e262..8f79088dec0f 100644
--- a/sw/source/core/inc/DocumentRedlineManager.hxx
+++ b/sw/source/core/inc/DocumentRedlineManager.hxx
@@ -76,6 +76,11 @@ public:
         /*[in]*/const SwNode& rNode,
         /*[in]*/RedlineType nType) const override;
 
+    virtual bool HasRedline(
+        /*[in]*/const SwPaM& rPam,
+        /*[in]*/RedlineType nType,
+        /*[in]*/bool bStartOrEndInRange) const override;
+
     virtual void CompressRedlines() override;
 
     virtual const SwRangeRedline* GetRedline(


More information about the Libreoffice-commits mailing list