[Libreoffice-commits] core.git: Branch 'libreoffice-5-3' - starmath/qa starmath/source

Takeshi Abe tabe at fixedpoint.jp
Thu Feb 23 12:31:40 UTC 2017


 starmath/qa/cppunit/test_starmath.cxx |    8 +++++++
 starmath/source/edit.cxx              |   36 +++++++++-------------------------
 2 files changed, 18 insertions(+), 26 deletions(-)

New commits:
commit eac1221ff124186887b23a2f7e7b57038bd08a43
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Tue Feb 21 12:48:33 2017 +0900

    tdf#106116 "Previous Marker" changes selection only when needed
    
    This fixes a hang caused by repeated Shift+F4. Although it seems
    a regression from 2af1f5691e8d64afd5246d245d7876b5a2cd5cd8,
    the original code of SmEditWindow::SelPrevMark() had been doomed
    due to conditional loop depending on obscure signed/unsigned
    conversion.
    
    Change-Id: I61f630eec44b285dc1f1c27097acde4b48ed2991
    Reviewed-on: https://gerrit.libreoffice.org/34503
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Takeshi Abe <tabe at fixedpoint.jp>
    (cherry picked from commit 3efdd925e0ae1c080fbef3f1f79865eb6e172c68)
    Reviewed-on: https://gerrit.libreoffice.org/34504
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/starmath/qa/cppunit/test_starmath.cxx b/starmath/qa/cppunit/test_starmath.cxx
index 05cddc5..f7f608c 100644
--- a/starmath/qa/cppunit/test_starmath.cxx
+++ b/starmath/qa/cppunit/test_starmath.cxx
@@ -133,6 +133,14 @@ void Test::editMarker()
         m_pEditWindow->Delete();
         m_pEditWindow->InsertText("b");
 
+        // tdf#106116: should be safe i.e. do nothing
+        m_pEditWindow->SelPrevMark();
+        auto aSelection = m_pEditWindow->GetSelection();
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSelection.nStartPara);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(9), aSelection.nStartPos);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSelection.nEndPara);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(9), aSelection.nEndPos);
+
         m_pEditWindow->Flush();
         OUString sFinalText = m_pEditWindow->GetText();
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be a under b under c", sTargetText, sFinalText);
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index 43fc755..ff473f9 100644
--- a/starmath/source/edit.cxx
+++ b/starmath/source/edit.cxx
@@ -878,36 +878,20 @@ void SmEditWindow::SelPrevMark()
     if (pEditEngine  &&  pEditView)
     {
         ESelection eSelection = pEditView->GetSelection();
-        sal_Int32 nPos = -1;
+        sal_Int32 nPara = eSelection.nStartPara;
         sal_Int32 nMax = eSelection.nStartPos;
-        OUString aText(pEditEngine->GetText(eSelection.nStartPara));
-        OUString aMark("<?>");
-        sal_Int32 nCounts = pEditEngine->GetParagraphCount();
-
-        do
-        {
-            sal_Int32 nMarkIndex = aText.indexOf(aMark);
-            while ((nMarkIndex < nMax) && (nMarkIndex != -1))
-            {
-                nPos = nMarkIndex;
-                nMarkIndex = aText.indexOf(aMark, nMarkIndex + 1);
-            }
-
-            if (nPos == -1)
-            {
-                eSelection.nStartPara--;
-                aText = pEditEngine->GetText(eSelection.nStartPara);
-                nMax = aText.getLength();
-            }
-        }
-        while ((eSelection.nStartPara < nCounts) &&
-            (nPos == -1));
+        OUString aText(pEditEngine->GetText(nPara));
+        const OUString aMark("<?>");
+        sal_Int32 nPos;
 
-        if (nPos != -1)
+        while ( (nPos = aText.lastIndexOf(aMark, nMax)) < 0 )
         {
-            pEditView->SetSelection(ESelection(
-                eSelection.nStartPara, nPos, eSelection.nStartPara, nPos + 3));
+            if (--nPara < 0)
+                return;
+            aText = pEditEngine->GetText(nPara);
+            nMax = aText.getLength();
         }
+        pEditView->SetSelection(ESelection(nPara, nPos, nPara, nPos + 3));
     }
 }
 


More information about the Libreoffice-commits mailing list