starmath/qa/cppunit/test_cursor.cxx |   20 ++++++++++++++++++++
 starmath/source/visitors.cxx        |    7 +++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

New commits:
commit d52feb11c7eab0adf82c1fb410adfd3127bf9497
Author:     Khaled Hosny <kha...@libreoffice.org>
AuthorDate: Mon Sep 11 20:32:22 2023 +0300
Commit:     خالد حسني <kha...@libreoffice.org>
CommitDate: Mon Sep 11 21:24:57 2023 +0200

    starmath: Fix selection of surrogate pairs in inline editing
    
    Don’t split nodes in the middle of surrogate pairs.
    
    Change-Id: I3ce8cf19d4c331e2ead73ed375745e8866b3d7a8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156827
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@libreoffice.org>

diff --git a/starmath/qa/cppunit/test_cursor.cxx 
b/starmath/qa/cppunit/test_cursor.cxx
index d76b446e6a41..f5be3f5beeaa 100644
--- a/starmath/qa/cppunit/test_cursor.cxx
+++ b/starmath/qa/cppunit/test_cursor.cxx
@@ -39,12 +39,14 @@ public:
     void testCopySelectPaste();
     void testCutPaste();
     void testCutSelectPaste();
+    void testSelectSurrogatePairs();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testCopyPaste);
     CPPUNIT_TEST(testCopySelectPaste);
     CPPUNIT_TEST(testCutPaste);
     CPPUNIT_TEST(testCutSelectPaste);
+    CPPUNIT_TEST(testSelectSurrogatePairs);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -172,6 +174,24 @@ void Test::testCutSelectPaste()
 #endif
 }
 
+void Test::testSelectSurrogatePairs()
+{
+    auto xTree = SmParser5().Parse(u"\U0001EE4E");
+    xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
+
+    SmCursor aCursor(xTree.get(), xDocShRef.get());
+    ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
+
+    // selct the first character, cut, then paste
+    aCursor.Move(pOutputDevice, MoveRight, false);
+    aCursor.Cut();
+    aCursor.Paste();
+
+#ifndef _WIN32 // FIXME: on Windows clipboard does not work in tests for some 
reason
+    CPPUNIT_ASSERT_EQUAL(OUString(u"\U0001EE4E"), xDocShRef->GetText());
+#endif
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 }
 
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 936097ccef3f..c2c4717df299 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -1040,8 +1040,11 @@ void SmCaretPosGraphBuildingVisitor::Visit( SmTextNode* 
pNode )
 {
     SAL_WARN_IF( pNode->GetText().isEmpty(), "starmath", "Empty SmTextNode is 
bad" );
 
-    int size = pNode->GetText().getLength();
-    for( int i = 1; i <= size; i++ ){
+    OUString& aText = pNode->GetText();
+    sal_Int32 i = 0;
+    while (i < aText.getLength())
+    {
+        aText.iterateCodePoints(&i);
         SmCaretPosGraphEntry* pRight = mpRightMost;
         mpRightMost = mpGraph->Add( SmCaretPos( pNode, i ), pRight );
         pRight->SetRight( mpRightMost );

Reply via email to