From 8d32930eaea539ef07a67aaa7f1d040cb2015251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 20 Apr 2018 11:34:02 +0200 Subject: [PATCH] [poincare] Check equivalent positions when moving Up and Down Change-Id: I5043d0a43c981592b0b72fd1221769497520b342 --- poincare/include/poincare/expression_layout.h | 5 ++- .../layout/binomial_coefficient_layout.cpp | 8 ++-- .../src/layout/binomial_coefficient_layout.h | 4 +- poincare/src/layout/condensed_sum_layout.cpp | 8 ++-- poincare/src/layout/condensed_sum_layout.h | 4 +- poincare/src/layout/expression_layout.cpp | 37 ++++++++++++++----- poincare/src/layout/fraction_layout.cpp | 8 ++-- poincare/src/layout/fraction_layout.h | 4 +- poincare/src/layout/grid_layout.cpp | 8 ++-- poincare/src/layout/grid_layout.h | 4 +- poincare/src/layout/integral_layout.cpp | 8 ++-- poincare/src/layout/integral_layout.h | 4 +- poincare/src/layout/matrix_layout.cpp | 8 ++-- poincare/src/layout/matrix_layout.h | 4 +- poincare/src/layout/nth_root_layout.cpp | 8 ++-- poincare/src/layout/nth_root_layout.h | 4 +- poincare/src/layout/sequence_layout.cpp | 8 ++-- poincare/src/layout/sequence_layout.h | 4 +- .../src/layout/vertical_offset_layout.cpp | 8 ++-- poincare/src/layout/vertical_offset_layout.h | 4 +- 20 files changed, 84 insertions(+), 66 deletions(-) diff --git a/poincare/include/poincare/expression_layout.h b/poincare/include/poincare/expression_layout.h index 3f49bed49..8de727f69 100644 --- a/poincare/include/poincare/expression_layout.h +++ b/poincare/include/poincare/expression_layout.h @@ -82,8 +82,8 @@ public: /* Tree navigation */ virtual bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; virtual bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; - virtual bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout); - virtual bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout); + virtual bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false); + virtual bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false); virtual bool moveUpInside(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout); virtual bool moveDownInside(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout); @@ -147,6 +147,7 @@ protected: bool m_positioned; private: void detachChildAtIndex(int i); + bool moveVertically(VerticalDirection direction, ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited); bool moveInside(VerticalDirection direction, ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout); ExpressionLayout * replaceWithJuxtapositionOf(ExpressionLayout * leftChild, ExpressionLayout * rightChild, bool deleteAfterReplace); KDRect m_frame; diff --git a/poincare/src/layout/binomial_coefficient_layout.cpp b/poincare/src/layout/binomial_coefficient_layout.cpp index a22e88e94..fce62238f 100644 --- a/poincare/src/layout/binomial_coefficient_layout.cpp +++ b/poincare/src/layout/binomial_coefficient_layout.cpp @@ -76,22 +76,22 @@ bool BinomialCoefficientLayout::moveRight(ExpressionLayoutCursor * cursor, bool return false; } -bool BinomialCoefficientLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool BinomialCoefficientLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // Case: kLayout. // Move to nLayout. if (cursor->pointedExpressionLayout()->hasAncestor(kLayout(), true)) { return nLayout()->moveUpInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool BinomialCoefficientLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool BinomialCoefficientLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // Case: nLayout. // Move to kLayout. if (cursor->pointedExpressionLayout()->hasAncestor(nLayout(), true)) { return kLayout()->moveDownInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } void BinomialCoefficientLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { diff --git a/poincare/src/layout/binomial_coefficient_layout.h b/poincare/src/layout/binomial_coefficient_layout.h index 0cb91941d..b59671b7f 100644 --- a/poincare/src/layout/binomial_coefficient_layout.h +++ b/poincare/src/layout/binomial_coefficient_layout.h @@ -13,8 +13,8 @@ public: ExpressionLayout * clone() const override; bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override { return LayoutEngine::writePrefixExpressionLayoutTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "binomial"); } diff --git a/poincare/src/layout/condensed_sum_layout.cpp b/poincare/src/layout/condensed_sum_layout.cpp index b1ae4ca16..4d597292e 100644 --- a/poincare/src/layout/condensed_sum_layout.cpp +++ b/poincare/src/layout/condensed_sum_layout.cpp @@ -90,7 +90,7 @@ bool CondensedSumLayout::moveRight(ExpressionLayoutCursor * cursor, bool * shoul return false; } -bool CondensedSumLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool CondensedSumLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside the subscript layout, move it to the superscript. if (subscriptLayout() && cursor->pointedExpressionLayout()->hasAncestor(subscriptLayout(), true)) { assert(superscriptLayout() != nullptr); @@ -104,10 +104,10 @@ bool CondensedSumLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRe assert(superscriptLayout() != nullptr); return superscriptLayout()->moveUpInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool CondensedSumLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool CondensedSumLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside the superscript layout, move it to the subscript. if (superscriptLayout() && cursor->pointedExpressionLayout()->hasAncestor(superscriptLayout(), true)) { assert(subscriptLayout() != nullptr); @@ -121,7 +121,7 @@ bool CondensedSumLayout::moveDown(ExpressionLayoutCursor * cursor, bool * should assert(subscriptLayout() != nullptr); return subscriptLayout()->moveUpInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } ExpressionLayout * CondensedSumLayout::layoutToPointWhenInserting() { diff --git a/poincare/src/layout/condensed_sum_layout.h b/poincare/src/layout/condensed_sum_layout.h index eafff7785..2f5164ae3 100644 --- a/poincare/src/layout/condensed_sum_layout.h +++ b/poincare/src/layout/condensed_sum_layout.h @@ -12,8 +12,8 @@ public: ExpressionLayout * clone() const override; bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override { return LayoutEngine::writePrefixExpressionLayoutTextInBuffer(this, buffer, bufferSize, numberOfSignificantDigits, "sum"); } diff --git a/poincare/src/layout/expression_layout.cpp b/poincare/src/layout/expression_layout.cpp index 458619abc..74b5eebca 100644 --- a/poincare/src/layout/expression_layout.cpp +++ b/poincare/src/layout/expression_layout.cpp @@ -237,22 +237,16 @@ char ExpressionLayout::XNTChar() const { return m_parent->XNTChar(); } -bool ExpressionLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { - if (m_parent) { - return m_parent->moveUp(cursor, shouldRecomputeLayout); - } - return false; +bool ExpressionLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { + return moveVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout, equivalentPositionVisited); } bool ExpressionLayout::moveUpInside(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { return moveInside(VerticalDirection::Up, cursor, shouldRecomputeLayout); } -bool ExpressionLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { - if (m_parent) { - return m_parent->moveDown(cursor, shouldRecomputeLayout); - } - return false; +bool ExpressionLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { + return moveVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout, equivalentPositionVisited); } bool ExpressionLayout::moveDownInside(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { @@ -343,6 +337,29 @@ bool ExpressionLayout::moveInside(VerticalDirection direction, ExpressionLayoutC return true; } +bool ExpressionLayout::moveVertically(VerticalDirection direction, ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { + if (!equivalentPositionVisited) { + ExpressionLayoutCursor cursorEquivalent = equivalentCursor(cursor); + if (cursorEquivalent.isDefined()) { + cursor->setPointedExpressionLayout(cursorEquivalent.pointedExpressionLayout()); + cursor->setPosition(cursorEquivalent.position()); + if (direction == VerticalDirection::Up) { + return cursor->pointedExpressionLayout()->moveUp(cursor, shouldRecomputeLayout, true); + } else { + return cursor->pointedExpressionLayout()->moveDown(cursor, shouldRecomputeLayout, true); + } + } + } + if (m_parent) { + if (direction == VerticalDirection::Up) { + return m_parent->moveUp(cursor, shouldRecomputeLayout, true); + } else { + return m_parent->moveDown(cursor, shouldRecomputeLayout, true); + } + } + return false; +} + void ExpressionLayout::moveCursorInsideAtDirection ( VerticalDirection direction, ExpressionLayoutCursor * cursor, diff --git a/poincare/src/layout/fraction_layout.cpp b/poincare/src/layout/fraction_layout.cpp index 98c30074b..7a485fb4a 100644 --- a/poincare/src/layout/fraction_layout.cpp +++ b/poincare/src/layout/fraction_layout.cpp @@ -143,7 +143,7 @@ bool FractionLayout::moveRight(ExpressionLayoutCursor * cursor, bool * shouldRec return false; } -bool FractionLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool FractionLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside denominator, move it to the numerator. if (denominatorLayout() && cursor->pointedExpressionLayout()->hasAncestor(denominatorLayout(), true)) { assert(numeratorLayout() != nullptr); @@ -154,10 +154,10 @@ bool FractionLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomp assert(numeratorLayout() != nullptr); return numeratorLayout()->moveUpInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool FractionLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool FractionLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside numerator, move it to the denominator. if (numeratorLayout() && cursor->pointedExpressionLayout()->hasAncestor(numeratorLayout(), true)) { assert(denominatorLayout() != nullptr); @@ -168,7 +168,7 @@ bool FractionLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldReco assert(denominatorLayout() != nullptr); return denominatorLayout()->moveDownInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } int FractionLayout::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits) const { diff --git a/poincare/src/layout/fraction_layout.h b/poincare/src/layout/fraction_layout.h index e1088a9b0..b329e4aae 100644 --- a/poincare/src/layout/fraction_layout.h +++ b/poincare/src/layout/fraction_layout.h @@ -14,8 +14,8 @@ public: void deleteBeforeCursor(ExpressionLayoutCursor * cursor) override; bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; ExpressionLayout * layoutToPointWhenInserting() override; bool canBeOmittedMultiplicationRightFactor() const override { return false; } diff --git a/poincare/src/layout/grid_layout.cpp b/poincare/src/layout/grid_layout.cpp index c83c9a5f3..601b8a502 100644 --- a/poincare/src/layout/grid_layout.cpp +++ b/poincare/src/layout/grid_layout.cpp @@ -94,7 +94,7 @@ bool GridLayout::moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecompu return false; } -bool GridLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool GridLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is child that is not on the top row, move it inside the upper // neighbourg. int childIndex = m_numberOfColumns; @@ -104,10 +104,10 @@ bool GridLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeL } childIndex++; } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool GridLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool GridLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { int childIndex = 0; while (childIndex < numberOfChildren() - m_numberOfColumns) { if (cursor->pointedExpressionLayout()->hasAncestor(child(childIndex), true)) { @@ -115,7 +115,7 @@ bool GridLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomput } childIndex++; } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } void GridLayout::removeChildAtIndex(int index, bool deleteAfterRemoval) { diff --git a/poincare/src/layout/grid_layout.h b/poincare/src/layout/grid_layout.h index 8e883d92c..d0e2313a8 100644 --- a/poincare/src/layout/grid_layout.h +++ b/poincare/src/layout/grid_layout.h @@ -15,8 +15,8 @@ public: /* Navigation */ bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; /* Dynamic layout */ void removeChildAtIndex(int index, bool deleteAfterRemoval) override; diff --git a/poincare/src/layout/integral_layout.cpp b/poincare/src/layout/integral_layout.cpp index 8791625ab..004f252c9 100644 --- a/poincare/src/layout/integral_layout.cpp +++ b/poincare/src/layout/integral_layout.cpp @@ -117,7 +117,7 @@ bool IntegralLayout::moveRight(ExpressionLayoutCursor * cursor, bool * shouldRec return false; } -bool IntegralLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool IntegralLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside the lower bound, move it to the upper bound. if (lowerBoundLayout() && cursor->pointedExpressionLayout()->hasAncestor(lowerBoundLayout(), true)) { assert(upperBoundLayout() != nullptr); @@ -131,10 +131,10 @@ bool IntegralLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomp assert(upperBoundLayout() != nullptr); return upperBoundLayout()->moveUpInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool IntegralLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool IntegralLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside the upper bound, move it to the lower bound. if (upperBoundLayout() && cursor->pointedExpressionLayout()->hasAncestor(upperBoundLayout(), true)) { assert(lowerBoundLayout() != nullptr); @@ -148,7 +148,7 @@ bool IntegralLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldReco assert(lowerBoundLayout() != nullptr); return lowerBoundLayout()->moveDownInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } int IntegralLayout::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits) const { diff --git a/poincare/src/layout/integral_layout.h b/poincare/src/layout/integral_layout.h index e8f377f3b..e8a7b8e74 100644 --- a/poincare/src/layout/integral_layout.h +++ b/poincare/src/layout/integral_layout.h @@ -19,8 +19,8 @@ public: /* Tree navigation */ bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; /* Expression Engine */ int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; diff --git a/poincare/src/layout/matrix_layout.cpp b/poincare/src/layout/matrix_layout.cpp index df13a623f..29bd302c5 100644 --- a/poincare/src/layout/matrix_layout.cpp +++ b/poincare/src/layout/matrix_layout.cpp @@ -80,7 +80,7 @@ bool MatrixLayout::moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecom return GridLayout::moveRight(cursor, shouldRecomputeLayout); } -bool MatrixLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool MatrixLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { bool shouldRemoveGreySquares = false; for (int childIndex = 0; childIndex < m_numberOfColumns; childIndex++) { if (cursor->pointedExpressionLayout()->hasAncestor(child(childIndex), true)) { @@ -89,7 +89,7 @@ bool MatrixLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomput break; } } - bool returnValue = GridLayout::moveUp(cursor, shouldRecomputeLayout); + bool returnValue = GridLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); if (returnValue && shouldRemoveGreySquares) { assert(hasGreySquares()); removeGreySquares(); @@ -98,7 +98,7 @@ bool MatrixLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomput return returnValue; } -bool MatrixLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool MatrixLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { bool shouldRemoveGreySquares = false; for (int childIndex = numberOfChildren() - m_numberOfColumns; childIndex < m_numberOfChildren; childIndex++) { if (cursor->pointedExpressionLayout()->hasAncestor(child(childIndex), true)) { @@ -107,7 +107,7 @@ bool MatrixLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomp break; } } - bool returnValue = GridLayout::moveDown(cursor, shouldRecomputeLayout); + bool returnValue = GridLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); if (returnValue && shouldRemoveGreySquares) { assert(hasGreySquares()); removeGreySquares(); diff --git a/poincare/src/layout/matrix_layout.h b/poincare/src/layout/matrix_layout.h index b4789595e..8a96f538e 100644 --- a/poincare/src/layout/matrix_layout.h +++ b/poincare/src/layout/matrix_layout.h @@ -13,8 +13,8 @@ public: /* Navigation */ bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; bool moveUpInside(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveDownInside(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; diff --git a/poincare/src/layout/nth_root_layout.cpp b/poincare/src/layout/nth_root_layout.cpp index ec605c3e9..7b5f35d3d 100644 --- a/poincare/src/layout/nth_root_layout.cpp +++ b/poincare/src/layout/nth_root_layout.cpp @@ -133,7 +133,7 @@ bool NthRootLayout::moveRight(ExpressionLayoutCursor * cursor, bool * shouldReco return false; } -bool NthRootLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool NthRootLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is Left of the radicand, move it to the index. if (indexLayout() && radicandLayout() @@ -153,10 +153,10 @@ bool NthRootLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecompu cursor->setPosition(ExpressionLayoutCursor::Position::Left); return true; } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool NthRootLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool NthRootLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { if (indexLayout() && cursor->pointedExpressionLayout()->hasAncestor(indexLayout(), true)) { // If the cursor is Right of the index, move it to the radicand. if (cursor->positionIsEquivalentTo(indexLayout(), ExpressionLayoutCursor::Position::Right)) { @@ -172,7 +172,7 @@ bool NthRootLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecom return true; } } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } static_assert('\x90' == Ion::Charset::Root, "Unicode error"); diff --git a/poincare/src/layout/nth_root_layout.h b/poincare/src/layout/nth_root_layout.h index 28e2d4956..ad562b75b 100644 --- a/poincare/src/layout/nth_root_layout.h +++ b/poincare/src/layout/nth_root_layout.h @@ -20,8 +20,8 @@ public: /* Tree navigation */ bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; /* Expression Engine */ int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; diff --git a/poincare/src/layout/sequence_layout.cpp b/poincare/src/layout/sequence_layout.cpp index 16fb1722f..c6531e706 100644 --- a/poincare/src/layout/sequence_layout.cpp +++ b/poincare/src/layout/sequence_layout.cpp @@ -98,7 +98,7 @@ bool SequenceLayout::moveRight(ExpressionLayoutCursor * cursor, bool * shouldRec return false; } -bool SequenceLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool SequenceLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside the lower bound, move it to the upper bound. if (lowerBoundLayout() && cursor->pointedExpressionLayout()->hasAncestor(lowerBoundLayout(), true)) { assert(upperBoundLayout() != nullptr); @@ -111,10 +111,10 @@ bool SequenceLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomp assert(upperBoundLayout() != nullptr); return upperBoundLayout()->moveUpInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool SequenceLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool SequenceLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // If the cursor is inside the upper bound, move it to the lower bound. if (upperBoundLayout() && cursor->pointedExpressionLayout()->hasAncestor(upperBoundLayout(), true)) { assert(lowerBoundLayout() != nullptr); @@ -127,7 +127,7 @@ bool SequenceLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldReco assert(lowerBoundLayout() != nullptr); return lowerBoundLayout()->moveDownInside(cursor, shouldRecomputeLayout); } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } ExpressionLayout * SequenceLayout::layoutToPointWhenInserting() { diff --git a/poincare/src/layout/sequence_layout.h b/poincare/src/layout/sequence_layout.h index 7c4343b9c..593259d91 100644 --- a/poincare/src/layout/sequence_layout.h +++ b/poincare/src/layout/sequence_layout.h @@ -13,8 +13,8 @@ public: void deleteBeforeCursor(ExpressionLayoutCursor * cursor) override; bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; ExpressionLayout * layoutToPointWhenInserting() override; char XNTChar() const override; protected: diff --git a/poincare/src/layout/vertical_offset_layout.cpp b/poincare/src/layout/vertical_offset_layout.cpp index 71c3e7afb..7ef567f0f 100644 --- a/poincare/src/layout/vertical_offset_layout.cpp +++ b/poincare/src/layout/vertical_offset_layout.cpp @@ -120,7 +120,7 @@ bool VerticalOffsetLayout::moveRight(ExpressionLayoutCursor * cursor, bool * sho return false; } -bool VerticalOffsetLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool VerticalOffsetLayout::moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // Case: Superscript. if (m_type == VerticalOffsetLayout::Type::Superscript) { // Case: Right. @@ -151,10 +151,10 @@ bool VerticalOffsetLayout::moveUp(ExpressionLayoutCursor * cursor, bool * should cursor->setPointedExpressionLayout(this); return true; } - return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -bool VerticalOffsetLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) { +bool VerticalOffsetLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { // Case: Subscript. if (m_type == VerticalOffsetLayout::Type::Subscript) { // Case: Right. @@ -184,7 +184,7 @@ bool VerticalOffsetLayout::moveDown(ExpressionLayoutCursor * cursor, bool * shou cursor->setPointedExpressionLayout(this); return true; } - return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout); + return ExpressionLayout::moveDown(cursor, shouldRecomputeLayout, equivalentPositionVisited); } int VerticalOffsetLayout::writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits) const { diff --git a/poincare/src/layout/vertical_offset_layout.h b/poincare/src/layout/vertical_offset_layout.h index d2aaaca8e..1b6cadb88 100644 --- a/poincare/src/layout/vertical_offset_layout.h +++ b/poincare/src/layout/vertical_offset_layout.h @@ -17,8 +17,8 @@ public: void deleteBeforeCursor(ExpressionLayoutCursor * cursor) override; bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; - bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; + bool moveUp(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + bool moveDown(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; int writeTextInBuffer(char * buffer, int bufferSize, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const override; bool mustHaveLeftSibling() const override { return true; } bool isVerticalOffset() const { return true; }