sw/qa/extras/uiwriter/uiwriter2.cxx |   30 ++++++++++++++++++++++++++++++
 sw/source/core/edit/edws.cxx        |    6 ++++++
 2 files changed, 36 insertions(+)

New commits:
commit e2076b31a91d3882f3deeaa5d3d4659da0e4b17c
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Mar 7 19:37:02 2022 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Mar 7 21:11:37 2022 +0100

    tdf#147414 sw_redlinehide: fix cursor position after AutoCorrect
    
    Change-Id: Ia06cd4e1a74a21788e4d0ddb5f0481e8a144d863
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131147
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index a784061ac0d5..63a56621a47e 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1509,6 +1509,36 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf109376)
     CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf147414)
+{
+    SwDoc* const pDoc(createSwDoc());
+    SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect());
+
+    pWrtShell->Insert("Abc");
+
+    // hide and enable
+    dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {});
+    dispatchCommand(mxComponent, ".uno:TrackChanges", {});
+
+    CPPUNIT_ASSERT(pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT(
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+    CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
+
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    // backspace
+    pWrtShell->DelLeft();
+    pWrtShell->AutoCorrect(corr, u' ');
+
+    // problem was this was 1 i.e. before the deleted "b" while " " was 
inserted after
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
+                         
pWrtShell->getShellCursor(false)->GetPoint()->nContent.GetIndex());
+    CPPUNIT_ASSERT_EQUAL(
+        OUString("Ab c"),
+        
pWrtShell->getShellCursor(false)->GetPoint()->nNode.GetNode().GetTextNode()->GetText());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf147310)
 {
     SwDoc* pDoc = createSwDoc();
diff --git a/sw/source/core/edit/edws.cxx b/sw/source/core/edit/edws.cxx
index 293a5f9f7960..647e59e11b5b 100644
--- a/sw/source/core/edit/edws.cxx
+++ b/sw/source/core/edit/edws.cxx
@@ -266,6 +266,12 @@ void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, 
bool bInsert,
     // FIXME: this _must_ be called with reference to the actual node text!
     SwTextFrame const*const pFrame(static_cast<SwTextFrame 
const*>(pTNd->getLayoutFrame(GetLayout())));
     TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
+    // tdf#147414 sw_redlinehide: if cursor moved backward, it may be at the
+    // start of a delete redline - but MapViewToModelPos() always returns end
+    // of redline and it will be called when AutoCorrect actually inserts
+    // something - so first normalize cursor point to end of redline so that
+    // point will then be moved forward when something is inserted.
+    *pCursor->GetPoint() = pFrame->MapViewToModelPos(nPos);
     OUString const& rMergedText(pFrame->GetText());
     rACorr.DoAutoCorrect( aSwAutoCorrDoc,
                     rMergedText, sal_Int32(nPos),

Reply via email to