sw/inc/IDocumentRedlineAccess.hxx | 5 +++ sw/qa/extras/uiwriter/uiwriter.cxx | 13 +++++--- sw/source/core/doc/DocumentRedlineManager.cxx | 29 ++++++++++++++++++ sw/source/core/edit/acorrect.cxx | 41 +++++++++----------------- sw/source/core/inc/DocumentRedlineManager.hxx | 5 +++ 5 files changed, 63 insertions(+), 30 deletions(-)
New commits: commit a2f9c539accc17cb980c35f810fa24f200c8bf1a Author: László Németh <nem...@numbertext.org> AuthorDate: Mon Nov 9 11:36:57 2020 +0100 Commit: Gabor Kelemen <kelemen.gab...@nisz.hu> CommitDate: Fri Apr 23 15:50:44 2021 +0200 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 <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114548 Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu> 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 8d2cd669630d..7b29b6026231 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -7538,8 +7538,14 @@ void SwUiWriterTest::testRedlineAutoCorrect() pWrtShell->Insert("et"); pWrtShell->AutoCorrect(corr, ' '); // This was "Ttest" removing the tracked deletion silently. - // FIXME The second patch from bug #83419 is missing from backport - sReplaced = "tstest "; + sReplaced = "tset "; + 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 "; nIndex = pWrtShell->GetCursor()->GetNode().GetIndex(); CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); @@ -7547,8 +7553,7 @@ void SwUiWriterTest::testRedlineAutoCorrect() dispatchCommand(mxComponent, ".uno:GoToStartOfDoc", {}); pWrtShell->Insert("a"); pWrtShell->AutoCorrect(corr, ' '); - // FIXME The second patch from bug #83419 is missing from backport - sReplaced = "A tstest "; + sReplaced = "A tset 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 f3aaa13a60d1..010a756af3e4 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 d48adc51557f..c872fde907cc 100644 --- a/sw/source/core/edit/acorrect.cxx +++ b/sw/source/core/edit/acorrect.cxx @@ -40,6 +40,9 @@ #include <svl/zformat.hxx> #include <editeng/acorrcfg.hxx> +#include <redline.hxx> +#include <IDocumentRedlineAccess.hxx> +#include <rootfrm.hxx> using namespace ::com::sun::star; @@ -229,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 ) @@ -422,8 +404,15 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, const bool replaceLastChar = sFrameText.getLength() > nEndPos && pFnd->GetShort()[0] == ':' && pFnd->GetShort().endsWith(":"); - SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(rSttPos)), - pFrame->MapViewToModelPos(TextFrameIndex(nEndPos + (replaceLastChar ? 1 : 0)))); + SwPosition aStartPos( pFrame->MapViewToModelPos(TextFrameIndex(rSttPos) )); + SwPosition aEndPos( pFrame->MapViewToModelPos(TextFrameIndex(nEndPos + (replaceLastChar ? 1 : 0))) ); + 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 ) ) + { + 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( _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits