[poincare/layout] Changed Fraction collapsing

Fraction are now only collapsed if they are the first thing to be
collapsed or if a parenthesis is open.

Change-Id: Ie7f3a99498b9981dff70221efd7de6bee6d0c379
This commit is contained in:
Gabriel Ozouf
2020-06-16 10:34:41 +02:00
committed by Émilie Feral
parent e295516928
commit e2e062e128
2 changed files with 19 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ public:
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const override;
bool shouldCollapseSiblingsOnLeft() const override { return true; }
bool shouldCollapseSiblingsOnRight() const override { return true; }
int leftCollapsingAbsorbingChildIndex() const override { return 0; }

View File

@@ -161,6 +161,24 @@ LayoutNode * FractionLayoutNode::layoutToPointWhenInserting(Expression * corresp
return this;
}
bool FractionLayoutNode::isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const {
if (*numberOfOpenParenthesis > 0) {
return true;
}
/* We do not want to absorb a fraction if something else is already being
* absorbed. This way, the user can write a product of fractions without
* typing the × sign. */
Layout p = Layout(parent());
assert(!p.isUninitialized() && p.type() == LayoutNode::Type::HorizontalLayout);
int indexInParent = p.indexOfChild(Layout(this));
int indexOfAbsorbingSibling = indexInParent + (goingLeft ? 1 : -1);
assert(indexOfAbsorbingSibling >= 0 && indexOfAbsorbingSibling < p.numberOfChildren());
Layout absorbingSibling = p.childAtIndex(indexOfAbsorbingSibling);
Layout absorbingChild = absorbingSibling.childAtIndex((goingLeft) ? absorbingSibling.leftCollapsingAbsorbingChildIndex() : absorbingSibling.rightCollapsingAbsorbingChildIndex());
return absorbingChild.type() == LayoutNode::Type::HorizontalLayout && absorbingChild.isEmpty();
}
void FractionLayoutNode::didCollapseSiblings(LayoutCursor * cursor) {
if (cursor != nullptr) {
cursor->setLayoutNode(denominatorLayout());