diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2022-03-07 19:37:02 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-03-18 21:37:59 +0100 |
commit | a5d474a7393a32a2f82294922940034330255596 (patch) | |
tree | 2991f26fc0da90e350d5114ecf8fe9d4687ff4b5 | |
parent | edcba0f739bc25b836b991cc4030aa9e2393b994 (diff) |
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.stahl@allotropia.de>
(cherry picked from commit e2076b31a91d3882f3deeaa5d3d4659da0e4b17c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131134
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
(cherry picked from commit ab0756c1b7509a034d0bb74251c519a090dedc7c)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131628
Tested-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 30 | ||||
-rw-r--r-- | sw/source/core/edit/edws.cxx | 6 |
2 files changed, 36 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index bc477d2ed42d..bdea12f0370a 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -1306,6 +1306,36 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf109376) CPPUNIT_ASSERT_EQUAL(size_t(1), pWrtShell->GetFlyCount(FLYCNTTYPE_FRM)); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf147414) +{ + SwDoc* const pDoc(createDoc()); + SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SwAutoCorrect corr(*SvxAutoCorrCfg::Get().GetAutoCorrect()); + + pWrtShell->Insert("Abc"); + + // hide and enable + lcl_dispatchCommand(mxComponent, ".uno:ShowTrackedChanges", {}); + lcl_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 = createDoc(); diff --git a/sw/source/core/edit/edws.cxx b/sw/source/core/edit/edws.cxx index dd5381cbb9eb..4991b9376a89 100644 --- a/sw/source/core/edit/edws.cxx +++ b/sw/source/core/edit/edws.cxx @@ -265,6 +265,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), |