From 31f46cec1406bb39453f5d909da1321980b0e405 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 5 Jun 2024 10:43:07 +0500 Subject: tdf#144752: UNDO/REDO: make sure to select the replaced content In the specific case of the bug, the non-empty selection means that the spell check won't skip the word with the cursor. But this also establishes consistency with other Undo/Redo cases, which generally select the text. Change-Id: Ib7c1c911908dc59947e610d735907be7a363ca87 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168423 Reviewed-by: Mike Kaganski Tested-by: Jenkins --- sw/qa/extras/uiwriter/uiwriter9.cxx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'sw/qa') diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx index a0918742a438..d35abf0b9b2f 100644 --- a/sw/qa/extras/uiwriter/uiwriter9.cxx +++ b/sw/qa/extras/uiwriter/uiwriter9.cxx @@ -648,6 +648,35 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf161172) CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty(para, u"NumberingLevel"_ustr)); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf144752) +{ + // Undoing/redoing a replacement must select the new text + createSwDoc(); + SwXTextDocument* pDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + emulateTyping(*pDoc, u"Some Text"); + CPPUNIT_ASSERT(!pWrtShell->HasSelection()); + // Select "Text", and replace with "Word" + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect*/ true, 4, /*bBasicCall*/ false); + pWrtShell->Replace(u"Word"_ustr, false); + pWrtShell->EndOfSection(); + CPPUNIT_ASSERT(!pWrtShell->HasSelection()); + + // Undo and check, that the "Text" is selected + dispatchCommand(mxComponent, ".uno:Undo", {}); + // Without the fix, this would fail + CPPUNIT_ASSERT(pWrtShell->HasSelection()); + CPPUNIT_ASSERT_EQUAL(u"Text"_ustr, pWrtShell->GetSelText()); + + // Redo and check, that the "Word" is selected + dispatchCommand(mxComponent, ".uno:Redo", {}); + CPPUNIT_ASSERT(pWrtShell->HasSelection()); + CPPUNIT_ASSERT_EQUAL(u"Word"_ustr, pWrtShell->GetSelText()); +} + } // end of anonymous namespace CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit