summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-03-07 19:37:02 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2022-03-10 10:34:57 +0100
commit8e63eb272ca0a75b2e800a63c47cf491715587a9 (patch)
treee04e8c504e3bf7cc09db90d0fb1c14623ff40e7a
parent6a1024962f7b286df0535b39e3b79202314245e0 (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/+/131135 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx30
-rw-r--r--sw/source/core/edit/edws.cxx6
2 files changed, 36 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 7e77a4eced99..3818ee546eed 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1549,6 +1549,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 e21469f6408b..eeec52f0eba1 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),