diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-11-11 08:41:50 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-11-11 09:57:20 +0100 |
commit | 2875c65946e59f5dd7968155463bf00bd71d440b (patch) | |
tree | 3461382a09bb7f576b33c551ddbbd8dd0fb4bf93 /sw/qa | |
parent | f69ce5f15e7fcae0b595e90631fd5ae2c76ed750 (diff) |
sw, out of order undo: allow a subset of a non-empty redo list
Specifically, we used to not allow out of order undo at all if the redo
list was non-empty. This relaxes that condition a bit. Out of order undo
is OK with a non-empty redo list, in case all undo actions in the redo
list are either
1) owned by the current view or
2) independent from the undo action to be executed
I.e. if view1 has lots of type undo actions and an view2 adds a
single type undo action on top of it, then allow view 1 to execute
multiple of its typing undo actions, not just a single one.
Change-Id: I2f5d9404a9994ed74b65233d2a315976c27b28b2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125023
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 46f1c781be02..4f0c7e3c5c7b 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -109,6 +109,7 @@ public: void testUndoInvalidations(); void testUndoLimiting(); void testUndoReordering(); + void testUndoReorderingRedo(); void testUndoShapeLimiting(); void testUndoDispatch(); void testUndoRepairDispatch(); @@ -191,6 +192,7 @@ public: CPPUNIT_TEST(testUndoInvalidations); CPPUNIT_TEST(testUndoLimiting); CPPUNIT_TEST(testUndoReordering); + CPPUNIT_TEST(testUndoReorderingRedo); CPPUNIT_TEST(testUndoShapeLimiting); CPPUNIT_TEST(testUndoDispatch); CPPUNIT_TEST(testUndoRepairDispatch); @@ -1352,6 +1354,60 @@ void SwTiledRenderingTest::testUndoReordering() SfxViewShell::Current()->setLibreOfficeKitViewCallback(nullptr); } +void SwTiledRenderingTest::testUndoReorderingRedo() +{ + // Create two views and a document of 2 paragraphs. + SwXTextDocument* pXTextDocument = createDoc(); + SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell(); + int nView1 = SfxLokHelper::getView(); + int nView2 = SfxLokHelper::createView(); + pXTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); + SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell2->SplitNode(); + SfxLokHelper::setView(nView1); + pWrtShell1->SttEndDoc(/*bStt=*/true); + SwTextNode* pTextNode1 = pWrtShell1->GetCursor()->GetNode().GetTextNode(); + // View 1 types into the first paragraph, twice. + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'f', 0); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'f', 0); + Scheduler::ProcessEventsToIdle(); + // Go to the start of the paragraph, to avoid grouping. + pWrtShell1->SttEndDoc(/*bStt=*/true); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 's', 0); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 's', 0); + Scheduler::ProcessEventsToIdle(); + SfxLokHelper::setView(nView2); + pWrtShell2->SttEndDoc(/*bStt=*/false); + SwTextNode* pTextNode2 = pWrtShell2->GetCursor()->GetNode().GetTextNode(); + // View 2 types into the second paragraph. + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'z', 0); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'z', 0); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(OUString("sf"), pTextNode1->GetText()); + CPPUNIT_ASSERT_EQUAL(OUString("z"), pTextNode2->GetText()); + + // When view 1 presses undo, twice: + SfxLokHelper::setView(nView1); + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + // First just s(econd) is erased: + CPPUNIT_ASSERT_EQUAL(OUString("f"), pTextNode1->GetText()); + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + + // Then make sure view 1's undo actions are invoked, out of order: + // Without the accompanying fix in place, this test would have failed with: + // - Expression: pTextNode1->GetText().isEmpty() + // i.e. out of order undo was executed only once, not twice. + CPPUNIT_ASSERT(pTextNode1->GetText().isEmpty()); + // The top undo action is not invoked, as it belongs to view 2. + CPPUNIT_ASSERT_EQUAL(OUString("z"), pTextNode2->GetText()); + SfxLokHelper::setView(nView1); + SfxViewShell::Current()->setLibreOfficeKitViewCallback(nullptr); + SfxLokHelper::setView(nView2); + SfxViewShell::Current()->setLibreOfficeKitViewCallback(nullptr); +} + void SwTiledRenderingTest::testUndoShapeLimiting() { // Load a document and create a view. |