summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-08-09 19:20:53 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2021-08-10 20:12:19 +0200
commit04f0cd819066229039203fb36848d907146bbba2 (patch)
treec3f984a57cc24ef107f0ec716a7bc9cc6dd3a1a2 /sd
parente77d6b92c51a8adf517fd283cf8984345bc3f8ce (diff)
tdf#142845 editeng: don't update selection when formatting before sd paste
Regression from commit f0c25c751cf8e166a84b289746bce6202a40391d (tdf#115783 sd: fix lost char attributes during in-table copy&paste, 2018-02-16), the problem was that the formatting before paste also created an undo action, and executing it alters the selection, which was not intended. So in case the textbox contains "world" and we paste "hello", then the undo will set the cursor at the end of "world", while the expected result is to just undo the paste and the formatting of "world". Fix the problem by not altering the selection in the undo of Outliner::SetCharAttribs(), which is only called by sd/ in the before-paste case, not anywhere else. (cherry picked from commit fc4c0747e97bb997cc37263b3e86b07dab21fe25) Change-Id: Ie4a08f57d22cd1862c02987a5f86089fda8a5d9d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120254 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sd')
-rw-r--r--sd/qa/unit/tiledrendering/data/paste-undo.fodp34
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx41
2 files changed, 75 insertions, 0 deletions
diff --git a/sd/qa/unit/tiledrendering/data/paste-undo.fodp b/sd/qa/unit/tiledrendering/data/paste-undo.fodp
new file mode 100644
index 000000000000..2615d1e11445
--- /dev/null
+++ b/sd/qa/unit/tiledrendering/data/paste-undo.fodp
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.presentation">
+ <office:styles>
+ <style:presentation-page-layout style:name="AL1T0">
+ <presentation:placeholder presentation:object="title" svg:x="2.058cm" svg:y="1.743cm" svg:width="23.912cm" svg:height="3.507cm"/>
+ <presentation:placeholder presentation:object="subtitle" svg:x="2.058cm" svg:y="5.838cm" svg:width="23.912cm" svg:height="13.23cm"/>
+ </style:presentation-page-layout>
+ </office:styles>
+ <office:automatic-styles>
+ <style:page-layout style:name="PM0">
+ <style:page-layout-properties fo:margin-top="0cm" fo:margin-bottom="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:page-width="21cm" fo:page-height="29.7cm" style:print-orientation="portrait"/>
+ </style:page-layout>
+ <style:page-layout style:name="PM1">
+ <style:page-layout-properties fo:margin-top="0cm" fo:margin-bottom="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:page-width="28cm" fo:page-height="15.75cm" style:print-orientation="landscape"/>
+ </style:page-layout>
+ <style:style style:name="dp3" style:family="drawing-page">
+ </style:style>
+ <style:style style:name="gr3" style:family="graphic" style:parent-style-name="standard">
+ <style:graphic-properties draw:stroke="none" svg:stroke-color="#000000" draw:fill="none" draw:fill-color="#ffffff" draw:auto-grow-height="true" draw:auto-grow-width="false" fo:max-height="0cm" fo:min-height="0.712cm"/>
+ <style:paragraph-properties style:writing-mode="lr-tb"/>
+ </style:style>
+ </office:automatic-styles>
+ <office:body>
+ <office:presentation>
+ <draw:page draw:name="page1" draw:style-name="dp3" draw:master-page-name="Default" presentation:presentation-page-layout-name="AL1T0">
+ <draw:frame draw:style-name="gr3" draw:text-style-name="P7" draw:layer="layout" svg:width="7.5cm" svg:height="0.962cm" svg:x="3.5cm" svg:y="3.5cm">
+ <draw:text-box>
+ <text:p>world</text:p>
+ </draw:text-box>
+ </draw:frame>
+ </draw:page>
+ </office:presentation>
+ </office:body>
+</office:document>
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 02856dd0043e..1bdd4c30386a 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -8,6 +8,9 @@
*/
#include "../sdmodeltestbase.hxx"
+
+#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
+
#include <app.hrc>
#include <test/bootstrapfixture.hxx>
#include <test/helper/transferable.hxx>
@@ -53,6 +56,7 @@
#include <vcl/cursor.hxx>
#include <vcl/scheduler.hxx>
#include <vcl/vclevent.hxx>
+#include <vcl/unohelp2.hxx>
#include <chrono>
#include <cstdlib>
@@ -133,6 +137,7 @@ public:
void testSlideDuplicateUndo();
void testMoveShapeHandle();
void testDeleteTable();
+ void testPasteUndo();
CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
CPPUNIT_TEST(testCreateDestroy);
@@ -190,6 +195,7 @@ public:
CPPUNIT_TEST(testSlideDuplicateUndo);
CPPUNIT_TEST(testMoveShapeHandle);
CPPUNIT_TEST(testDeleteTable);
+ CPPUNIT_TEST(testPasteUndo);
CPPUNIT_TEST_SUITE_END();
@@ -2679,6 +2685,41 @@ void SdTiledRenderingTest::testMoveShapeHandle()
}
}
+
+void SdTiledRenderingTest::testPasteUndo()
+{
+ // Given a document with a textbox, containing "world":
+ SdXImpressDocument* pXImpressDocument = createDoc("paste-undo.fodp");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ SdPage* pActualPage = pViewShell->GetActualPage();
+ SdrObject* pObject = pActualPage->GetObj(0);
+ SdrView* pView = pViewShell->GetView();
+ pView->MarkObj(pObject, pView->GetSdrPageView());
+ pView->SdrBeginTextEdit(pObject);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_HOME);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_HOME);
+ EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView();
+ ESelection aWordSelection(0, 0, 0, 1); // "w" of "world"
+ rEditView.SetSelection(aWordSelection);
+ comphelper::dispatchCommand(".uno:Cut", {});
+ Scheduler::ProcessEventsToIdle();
+
+ // When undoing a paste:
+ comphelper::dispatchCommand(".uno:Paste", {});
+ Scheduler::ProcessEventsToIdle();
+ comphelper::dispatchCommand(".uno:Undo", {});
+ Scheduler::ProcessEventsToIdle();
+
+ // Then make sure the cursor position is still at the beginning:
+ ESelection aSelection = rEditView.GetSelection();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 0
+ // - Actual : 4
+ // i.e. the cursor position after undo was at the end of the line, not at the start, as
+ // expected.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aSelection.nStartPos);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();