summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@libreoffice.org>2023-09-11 20:32:22 +0300
committerخالد حسني <khaled@libreoffice.org>2023-09-11 21:24:57 +0200
commitd52feb11c7eab0adf82c1fb410adfd3127bf9497 (patch)
tree4e4d3a09e44d2d20dc66178dd40c48d9581f92e2 /starmath
parentbf11a197519f6637b5a4f1f42436c2c9f262ef97 (diff)
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: خالد حسني <khaled@libreoffice.org>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/qa/cppunit/test_cursor.cxx20
-rw-r--r--starmath/source/visitors.cxx7
2 files changed, 25 insertions, 2 deletions
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 );