sd/qa/uitest/data/tdf153161_FlushToSave.odp |binary
 sd/qa/uitest/impress_tests2/tdf153161.py    |   37 ++++++++++++++++++++++++++++
 xmloff/source/draw/shapeexport.cxx          |   12 +++++++++
 3 files changed, 49 insertions(+)

New commits:
commit 8a53a45dfc6fb126ef4e60038df385a2b72effd9
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jan 25 01:37:00 2023 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Jan 25 11:17:23 2023 +0000

    tdf#153161: (Ab)use a call to XTextRange::getString to flush edits
    
    Restore the call (without checking its returned value), removed in commit
    d194474aabd699806cb3631bc8641dd0548b8026 ("tdf#151100: xText->getString()
    may be empty for content needing export", 2022-09-22), side effects of
    which obviously allow some object's changes to get flushed and saved.
    
    Change-Id: I62f27cd056c32ad76f79a4862e2f4a0964eaadef
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146106
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit d183daea1abbd7b564d083298874dd7c40d5a5b3)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146080
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sd/qa/uitest/data/tdf153161_FlushToSave.odp 
b/sd/qa/uitest/data/tdf153161_FlushToSave.odp
new file mode 100644
index 000000000000..1fd5c20c2a52
Binary files /dev/null and b/sd/qa/uitest/data/tdf153161_FlushToSave.odp differ
diff --git a/sd/qa/uitest/impress_tests2/tdf153161.py 
b/sd/qa/uitest/impress_tests2/tdf153161.py
new file mode 100644
index 000000000000..db14d7986f5b
--- /dev/null
+++ b/sd/qa/uitest/impress_tests2/tdf153161.py
@@ -0,0 +1,37 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_url_for_data_file
+
+class TestTdf153161(UITestCase):
+
+    def testTdf153161(self):
+        url = get_url_for_data_file('tdf153161_FlushToSave.odp')
+
+        with self.ui_test.load_file(url) as document:
+            oldText = document.DrawPages[0].getByIndex(1).String
+            self.assertTrue(oldText.startswith('在没有版本控制系统的时期'))
+
+            xImpressDoc = self.xUITest.getTopFocusWindow()
+            xEditWin = xImpressDoc.getChild('impress_win')
+            xEditWin.executeAction('SELECT', 
mkPropertyValues({'OBJECT':'Unnamed Drawinglayer object 1'}))
+
+            # Type something, getting into text editing mode (appending) 
automatically
+            xEditWin.executeAction('TYPE', mkPropertyValues({'TEXT': 'Foo 
Bar'}))
+            xToolkit = 
self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
+            xToolkit.processEventsToIdle()
+            self.xUITest.executeCommand('.uno:Save')
+
+        # Reload and check that the edit was saved
+        with self.ui_test.load_file(url) as document:
+            self.assertEqual(oldText + 'Foo Bar', 
document.DrawPages[0].getByIndex(1).String)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/xmloff/source/draw/shapeexport.cxx 
b/xmloff/source/draw/shapeexport.cxx
index 51ee4c894250..6e687e746ba4 100644
--- a/xmloff/source/draw/shapeexport.cxx
+++ b/xmloff/source/draw/shapeexport.cxx
@@ -310,6 +310,18 @@ void XMLShapeExport::collectShapeAutoStyles(const 
uno::Reference< drawing::XShap
         uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY);
         if (xText.is())
         {
+            try
+            {
+                // tdf#153161: it seems that the call to XTextRange::getString 
flushes the changes
+                // for some objects, that otherwise fail to get exported 
correctly. Maybe at some
+                // point it would make sense to find a better place for more 
targeted flush.
+                xText->getString();
+            }
+            catch (uno::RuntimeException const&)
+            {
+                // E.g., SwXTextFrame that contains only a table will throw; 
this is not an error
+            }
+
             uno::Reference< beans::XPropertySetInfo > xPropSetInfo( 
xPropSet->getPropertySetInfo() );
 
             if( xPropSetInfo.is() && 
xPropSetInfo->hasPropertyByName("IsEmptyPresentationObject") )

Reply via email to