summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@libreoffice.org>2023-09-07 10:21:24 +0300
committerخالد حسني <khaled@libreoffice.org>2023-09-07 16:18:28 +0200
commit8c982bf86ff9ca5a4ed86505ec1133cc183f1b58 (patch)
tree65d27e550d7cd972b103601a931e56b01ee49602 /starmath
parente59516e8b31f0a1880de153229f5b193a447fb60 (diff)
tdf#130741: Insert brackets around horizontal binary nodes more generously
When converting node tree creating with visual editor back to text for the command editor, try to always insert brackets around binary expressions. It might look redundant at times but it is safer, and the code is not supposed to be edited by hand anymore so doesn’t have to look pretty. Change-Id: Ifff574494c9e8f8b948e432f6832d88c334aba00 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156640 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@libreoffice.org>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/qa/cppunit/test_cursor.cxx10
-rw-r--r--starmath/qa/cppunit/test_nodetotextvisitors.cxx4
-rw-r--r--starmath/source/visitors.cxx4
3 files changed, 9 insertions, 9 deletions
diff --git a/starmath/qa/cppunit/test_cursor.cxx b/starmath/qa/cppunit/test_cursor.cxx
index 5f4c551675a1..bbdebf503153 100644
--- a/starmath/qa/cppunit/test_cursor.cxx
+++ b/starmath/qa/cppunit/test_cursor.cxx
@@ -87,7 +87,7 @@ void Test::testCopyPaste()
aCursor.Move(pOutputDevice, MoveRight);
aCursor.Paste();
- CPPUNIT_ASSERT_EQUAL(OUString("{ a * b + c * b }"), xDocShRef->GetText());
+ CPPUNIT_ASSERT_EQUAL(OUString("{ { a * b } + { c * b } }"), xDocShRef->GetText());
}
void Test::testCopySelectPaste()
@@ -113,7 +113,7 @@ void Test::testCopySelectPaste()
aCursor.Move(pOutputDevice, MoveRight, false);
aCursor.Paste();
- CPPUNIT_ASSERT_EQUAL(OUString("{ b + c * b + c }"), xDocShRef->GetText());
+ CPPUNIT_ASSERT_EQUAL(OUString("{ { b + { c * b } } + c }"), xDocShRef->GetText());
}
void Test::testCutPaste()
@@ -130,12 +130,12 @@ void Test::testCutPaste()
aCursor.Move(pOutputDevice, MoveRight, false);
aCursor.Move(pOutputDevice, MoveRight, false);
aCursor.Cut();
- // go to the left end and then paste
+ // go to the right end and then paste
aCursor.Move(pOutputDevice, MoveRight);
aCursor.Move(pOutputDevice, MoveRight);
aCursor.Paste();
- CPPUNIT_ASSERT_EQUAL(OUString("{ a + c * b }"), xDocShRef->GetText());
+ CPPUNIT_ASSERT_EQUAL(OUString("{ a + { c * b } }"), xDocShRef->GetText());
}
void Test::testCutSelectPaste()
@@ -161,7 +161,7 @@ void Test::testCutSelectPaste()
aCursor.Move(pOutputDevice, MoveRight, false);
aCursor.Paste();
- CPPUNIT_ASSERT_EQUAL(OUString("{ b + c * }"), xDocShRef->GetText());
+ CPPUNIT_ASSERT_EQUAL(OUString("{ b + { c * } }"), xDocShRef->GetText());
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
index 11ef5affcc4c..aba582e281d3 100644
--- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx
+++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
@@ -528,7 +528,7 @@ void Test::testBinomInBinHor()
aCursor.InsertElement(PlusElement);
aCursor.InsertText("d");
- sExpected += "{ { binom a b + c } + d }";
+ sExpected += "{ { binom a { b + c } } + d }";
CPPUNIT_ASSERT_EQUAL_MESSAGE("Binom Node in BinHor Node", sExpected, xDocShRef->GetText());
}
@@ -623,7 +623,7 @@ void Test::testUnaryInMixedNumberAsNumerator()
aCursor.InsertText("4");
CPPUNIT_ASSERT_EQUAL_MESSAGE("Unary in mixed number as Numerator",
- OUString("{ 2 { - 1 over 2 } + 4 }"), xDocShRef->GetText());
+ OUString("{ 2 { { - 1 over 2 } + 4 } }"), xDocShRef->GetText());
}
void Test::testMiscEquivalent()
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 732c27f9840f..b205e710b72f 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -2189,7 +2189,7 @@ void SmNodeToTextVisitor::Visit( SmUnHorNode* pNode )
void SmNodeToTextVisitor::Visit( SmBinHorNode* pNode )
{
const SmNode *pParent = pNode->GetParent();
- bool bBraceNeeded = pParent && pParent->GetType() == SmNodeType::Font;
+ bool bBraceNeeded = pParent;
SmNode *pLeft = pNode->LeftOperand(),
*pOper = pNode->Symbol(),
*pRight = pNode->RightOperand();
@@ -2598,7 +2598,7 @@ void SmNodeToTextVisitor::Visit( SmLineNode* pNode )
void SmNodeToTextVisitor::Visit( SmExpressionNode* pNode )
{
- bool bracketsNeeded = pNode->GetNumSubNodes() != 1 || pNode->GetSubNode(0)->GetType() == SmNodeType::BinHor;
+ bool bracketsNeeded = pNode->GetNumSubNodes() != 1;
if (!bracketsNeeded)
{
const SmNode *pParent = pNode->GetParent();