diff --git a/poincare/include/poincare/binomial_coefficient_layout.h b/poincare/include/poincare/binomial_coefficient_layout.h index 6f39472e3..210207062 100644 --- a/poincare/include/poincare/binomial_coefficient_layout.h +++ b/poincare/include/poincare/binomial_coefficient_layout.h @@ -15,10 +15,10 @@ public: Type type() const override { return Type::BinomialCoefficientLayout; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; // SerializableNode int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; diff --git a/poincare/include/poincare/bracket_layout.h b/poincare/include/poincare/bracket_layout.h index 3a1e4d329..513f1ef9e 100644 --- a/poincare/include/poincare/bracket_layout.h +++ b/poincare/include/poincare/bracket_layout.h @@ -15,8 +15,8 @@ public: {} // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; void invalidAllSizesPositionsAndBaselines() override; // TreeNode diff --git a/poincare/include/poincare/bracket_pair_layout.h b/poincare/include/poincare/bracket_pair_layout.h index 259a95bb8..f1fcd0879 100644 --- a/poincare/include/poincare/bracket_pair_layout.h +++ b/poincare/include/poincare/bracket_pair_layout.h @@ -16,8 +16,8 @@ public: static void RenderWithChildSize(KDSize childSize, KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor); // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; void deleteBeforeCursor(LayoutCursor * cursor) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; bool shouldCollapseSiblingsOnRight() const override{ return true; } diff --git a/poincare/include/poincare/code_point_layout.h b/poincare/include/poincare/code_point_layout.h index 3af1c1975..d8d4dfbbf 100644 --- a/poincare/include/poincare/code_point_layout.h +++ b/poincare/include/poincare/code_point_layout.h @@ -28,8 +28,8 @@ public: const KDFont * font() const { return m_font; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const override; bool canBeOmittedMultiplicationLeftFactor() const override; diff --git a/poincare/include/poincare/condensed_sum_layout.h b/poincare/include/poincare/condensed_sum_layout.h index 7c340c9ff..6f5bb5e88 100644 --- a/poincare/include/poincare/condensed_sum_layout.h +++ b/poincare/include/poincare/condensed_sum_layout.h @@ -18,10 +18,10 @@ public: /* CondensedSumLayout is only used in apps/shared/sum_graph_controller.cpp, in * a view with no cursor. */ - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override { assert(false); } - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override { assert(false); } - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override { assert(false); } - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override { assert(false); } + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override { assert(false); } + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override { assert(false); } + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) override { assert(false); } + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) override { assert(false); } int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { assert(false); return 0; diff --git a/poincare/include/poincare/conjugate_layout.h b/poincare/include/poincare/conjugate_layout.h index 1fa23ae15..e56187c77 100644 --- a/poincare/include/poincare/conjugate_layout.h +++ b/poincare/include/poincare/conjugate_layout.h @@ -14,8 +14,8 @@ public: Type type() const override { return Type::ConjugateLayout; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; bool shouldCollapseSiblingsOnRight() const override { return true; } diff --git a/poincare/include/poincare/empty_layout.h b/poincare/include/poincare/empty_layout.h index b29d63c08..8361c09b5 100644 --- a/poincare/include/poincare/empty_layout.h +++ b/poincare/include/poincare/empty_layout.h @@ -32,8 +32,8 @@ public: // LayoutNode void deleteBeforeCursor(LayoutCursor * cursor) override; - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; bool isEmpty() const override { return true; } bool hasText() const override { return false; } @@ -63,7 +63,7 @@ private: KDCoordinate width() const { return m_font->glyphSize().width() - 2 * k_marginWidth; } // LayoutNode - void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) override; + void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) override; bool willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) override; void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart = nullptr, Layout * selectionEnd = nullptr, KDColor selectionColor = KDColorRed) override; bool protectedIsIdenticalTo(Layout l) override; diff --git a/poincare/include/poincare/fraction_layout.h b/poincare/include/poincare/fraction_layout.h index d8cb07a46..68b7cbb12 100644 --- a/poincare/include/poincare/fraction_layout.h +++ b/poincare/include/poincare/fraction_layout.h @@ -14,10 +14,10 @@ public: Type type() const override { return Type::FractionLayout; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; void deleteBeforeCursor(LayoutCursor * cursor) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; diff --git a/poincare/include/poincare/grid_layout.h b/poincare/include/poincare/grid_layout.h index 6d81e5304..91890c5b0 100644 --- a/poincare/include/poincare/grid_layout.h +++ b/poincare/include/poincare/grid_layout.h @@ -32,10 +32,10 @@ public: KDSize gridSize() const { return KDSize(width(), height()); } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; // SerializableNode int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { diff --git a/poincare/include/poincare/horizontal_layout.h b/poincare/include/poincare/horizontal_layout.h index 381965694..7c9b5ae2c 100644 --- a/poincare/include/poincare/horizontal_layout.h +++ b/poincare/include/poincare/horizontal_layout.h @@ -24,8 +24,8 @@ public: Type type() const override { return Type::HorizontalLayout; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; LayoutCursor equivalentCursor(LayoutCursor * cursor) override; void deleteBeforeCursor(LayoutCursor * cursor) override; LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression) override; diff --git a/poincare/include/poincare/integral_layout.h b/poincare/include/poincare/integral_layout.h index 437c04b2e..c714c8327 100644 --- a/poincare/include/poincare/integral_layout.h +++ b/poincare/include/poincare/integral_layout.h @@ -18,10 +18,10 @@ public: Type type() const override { return Type::IntegralLayout; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; void deleteBeforeCursor(LayoutCursor * cursor) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression) override { return lowerBoundLayout(); } diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index edd98e13f..12fcfd3a0 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -82,24 +82,20 @@ public: KDPoint middleLeftPoint(); /* Move */ - void move(Direction direction, bool * shouldRecomputeLayout); - void moveLeft(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorLeft(this, shouldRecomputeLayout); + void move(Direction direction, bool * shouldRecomputeLayout, bool forSelection = false); + void moveLeft(bool * shouldRecomputeLayout, bool forSelection = false) { + layoutNode()->moveCursorLeft(this, shouldRecomputeLayout, forSelection); } - void moveRight(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorRight(this, shouldRecomputeLayout); + void moveRight(bool * shouldRecomputeLayout, bool forSelection = false) { + layoutNode()->moveCursorRight(this, shouldRecomputeLayout, forSelection); } - void moveAbove(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorUp(this, shouldRecomputeLayout); + void moveAbove(bool * shouldRecomputeLayout, bool forSelection = false) { + layoutNode()->moveCursorUp(this, shouldRecomputeLayout, false, forSelection); } - void moveUnder(bool * shouldRecomputeLayout) { - layoutNode()->moveCursorDown(this, shouldRecomputeLayout); - } - LayoutCursor cursorAtDirection(Direction direction, bool * shouldRecomputeLayout) { - LayoutCursor result = clone(); - result.move(direction, shouldRecomputeLayout); - return result; + void moveUnder(bool * shouldRecomputeLayout, bool forSelection = false) { + layoutNode()->moveCursorDown(this, shouldRecomputeLayout, false, forSelection); } + LayoutCursor cursorAtDirection(Direction direction, bool * shouldRecomputeLayout, bool forSelection = false); /* Select */ void select(Direction direction, bool * shouldRecomputeLayout, Layout * selection); diff --git a/poincare/include/poincare/layout_node.h b/poincare/include/poincare/layout_node.h index 03717277f..9b4f9a5f1 100644 --- a/poincare/include/poincare/layout_node.h +++ b/poincare/include/poincare/layout_node.h @@ -75,19 +75,19 @@ public: LayoutNode * root() override { return static_cast(TreeNode::root()); } // Tree navigation - virtual void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; - virtual void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) = 0; - virtual void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) { - moveCursorVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout, equivalentPositionVisited); + virtual void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection = false) = 0; + virtual void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection = false) = 0; + virtual void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) { + moveCursorVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout, equivalentPositionVisited, forSelection); } - virtual void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) { - moveCursorVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout, equivalentPositionVisited); + virtual void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) { + moveCursorVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout, equivalentPositionVisited, forSelection); } - void moveCursorUpInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout) { - return moveCursorInDescendantsVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout); + void moveCursorUpInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection = false) { + return moveCursorInDescendantsVertically(VerticalDirection::Up, cursor, shouldRecomputeLayout, forSelection); } - void moveCursorDownInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout) { - return moveCursorInDescendantsVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout); + void moveCursorDownInDescendants(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection = false) { + return moveCursorInDescendantsVertically(VerticalDirection::Down, cursor, shouldRecomputeLayout, forSelection); } virtual LayoutCursor equivalentCursor(LayoutCursor * cursor); @@ -143,7 +143,7 @@ protected: virtual bool protectedIsIdenticalTo(Layout l); // Tree navigation - virtual void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited); + virtual void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection); // Tree Direct children() { return Direct(this); } @@ -163,14 +163,15 @@ protected: bool m_positioned; bool m_sized; private: - void moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout); + void moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection); void scoreCursorInDescendantsVertically ( VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, LayoutNode ** childResult, void * resultPosition, - int * resultScore); + int * resultScore, + bool forSelection); virtual void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart = nullptr, Layout * selectionEnd = nullptr, KDColor selectionColor = KDColorRed) = 0; bool changeGreySquaresOfAllMatrixAncestors(bool add); }; diff --git a/poincare/include/poincare/matrix_layout.h b/poincare/include/poincare/matrix_layout.h index 9f7a5b430..cda42e202 100644 --- a/poincare/include/poincare/matrix_layout.h +++ b/poincare/include/poincare/matrix_layout.h @@ -23,8 +23,8 @@ public: void removeGreySquares(); // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; void willAddSiblingToEmptyChildAtIndex(int childIndex) override; void deleteBeforeCursor(LayoutCursor * cursor) override; @@ -43,7 +43,7 @@ protected: // LayoutNode KDSize computeSize() override; KDPoint positionOfChild(LayoutNode * l) override; - void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) override; + void moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) override; private: // MatrixNode diff --git a/poincare/include/poincare/nth_root_layout.h b/poincare/include/poincare/nth_root_layout.h index fa91328da..ba5cff8ce 100644 --- a/poincare/include/poincare/nth_root_layout.h +++ b/poincare/include/poincare/nth_root_layout.h @@ -25,10 +25,10 @@ public: Type type() const override { return Type::NthRootLayout; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; void deleteBeforeCursor(LayoutCursor * cursor) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; bool shouldCollapseSiblingsOnRight() const override { return true; } diff --git a/poincare/include/poincare/sequence_layout.h b/poincare/include/poincare/sequence_layout.h index 4d1942317..7f37b0ffc 100644 --- a/poincare/include/poincare/sequence_layout.h +++ b/poincare/include/poincare/sequence_layout.h @@ -14,10 +14,10 @@ public: using LayoutNode::LayoutNode; // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; void deleteBeforeCursor(LayoutCursor * cursor) override; LayoutNode * layoutToPointWhenInserting(Expression * correspondingExpression) override { return lowerBoundLayout(); } CodePoint XNTCodePoint(int childIndex = -1) const override; diff --git a/poincare/include/poincare/vertical_offset_layout.h b/poincare/include/poincare/vertical_offset_layout.h index 43b4b4163..5a36cc666 100644 --- a/poincare/include/poincare/vertical_offset_layout.h +++ b/poincare/include/poincare/vertical_offset_layout.h @@ -25,10 +25,10 @@ public: Position position() const { return m_position; } // LayoutNode - void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override; - void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; - void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false) override; + void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) override; + void moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; + void moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited = false, bool forSelection = false) override; void deleteBeforeCursor(LayoutCursor * cursor) override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; bool mustHaveLeftSibling() const override { return true; } diff --git a/poincare/src/binomial_coefficient_layout.cpp b/poincare/src/binomial_coefficient_layout.cpp index 6b3053d2e..962a42894 100644 --- a/poincare/src/binomial_coefficient_layout.cpp +++ b/poincare/src/binomial_coefficient_layout.cpp @@ -9,7 +9,7 @@ namespace Poincare { static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } -void BinomialCoefficientLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void BinomialCoefficientLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Left && (cursor->layoutNode() == nLayout() || cursor->layoutNode() == kLayout())) @@ -33,7 +33,7 @@ void BinomialCoefficientLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * } } -void BinomialCoefficientLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void BinomialCoefficientLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Right && (cursor->layoutNode() == nLayout() || cursor->layoutNode() == kLayout())) @@ -57,7 +57,7 @@ void BinomialCoefficientLayoutNode::moveCursorRight(LayoutCursor * cursor, bool } } -void BinomialCoefficientLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void BinomialCoefficientLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(kLayout(), true)) { // Case: kLayout. Move to nLayout. return nLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout); @@ -65,7 +65,7 @@ void BinomialCoefficientLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * s LayoutNode::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -void BinomialCoefficientLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void BinomialCoefficientLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(nLayout(), true)) { // Case: nLayout. Move to kLayout. return kLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout); diff --git a/poincare/src/bracket_layout.cpp b/poincare/src/bracket_layout.cpp index 2b22c8aa5..fa883e17c 100644 --- a/poincare/src/bracket_layout.cpp +++ b/poincare/src/bracket_layout.cpp @@ -7,7 +7,7 @@ namespace Poincare { static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } -void BracketLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void BracketLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { assert(cursor->layoutNode() == this); if (cursor->position() == LayoutCursor::Position::Right) { // Case: Right. Go Left. @@ -22,7 +22,7 @@ void BracketLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecom } } -void BracketLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void BracketLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { assert(cursor->layoutNode() == this); if (cursor->position() == LayoutCursor::Position::Left) { // Case: Left. Go Right. diff --git a/poincare/src/bracket_pair_layout.cpp b/poincare/src/bracket_pair_layout.cpp index a919603cf..b42a930b5 100644 --- a/poincare/src/bracket_pair_layout.cpp +++ b/poincare/src/bracket_pair_layout.cpp @@ -23,7 +23,7 @@ void BracketPairLayoutNode::RenderWithChildSize(KDSize childSize, KDContext * ct ctx->fillRect(KDRect(p.x()+k_externWidthMargin+2*k_lineThickness+childSize.width()+2*k_widthMargin-k_bracketWidth, p.y()+k_verticalExternMargin+verticalBarHeight-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor); } -void BracketPairLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void BracketPairLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == childLayout() && cursor->position() == LayoutCursor::Position::Left) { @@ -45,7 +45,7 @@ void BracketPairLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldR } } -void BracketPairLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void BracketPairLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == childLayout() && cursor->position() == LayoutCursor::Position::Right) { diff --git a/poincare/src/code_point_layout.cpp b/poincare/src/code_point_layout.cpp index 8eeff264a..b85913194 100644 --- a/poincare/src/code_point_layout.cpp +++ b/poincare/src/code_point_layout.cpp @@ -5,7 +5,7 @@ namespace Poincare { // LayoutNode -void CodePointLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void CodePointLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Right) { cursor->setPosition(LayoutCursor::Position::Left); return; @@ -16,7 +16,7 @@ void CodePointLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRec } } -void CodePointLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void CodePointLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Left) { cursor->setPosition(LayoutCursor::Position::Right); return; diff --git a/poincare/src/conjugate_layout.cpp b/poincare/src/conjugate_layout.cpp index fbf60948c..033ce4bce 100644 --- a/poincare/src/conjugate_layout.cpp +++ b/poincare/src/conjugate_layout.cpp @@ -7,7 +7,7 @@ namespace Poincare { -void ConjugateLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void ConjugateLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == childLayout() && cursor->position() == LayoutCursor::Position::Left) { @@ -29,7 +29,7 @@ void ConjugateLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRec } } -void ConjugateLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void ConjugateLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { // Case: Right of the operand. Move Right. if (cursor->layoutNode() == childLayout() && cursor->position() == LayoutCursor::Position::Right) diff --git a/poincare/src/empty_layout.cpp b/poincare/src/empty_layout.cpp index 03f1ccc08..bb9582856 100644 --- a/poincare/src/empty_layout.cpp +++ b/poincare/src/empty_layout.cpp @@ -13,7 +13,7 @@ void EmptyLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { } } -void EmptyLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void EmptyLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { assert(cursor->layoutNode() == this); // Ask the parent. LayoutNode * p = parent(); @@ -23,7 +23,7 @@ void EmptyLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecompu } } -void EmptyLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void EmptyLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { assert(cursor->layoutNode() == this); // Ask the parent. LayoutNode * p = parent(); @@ -50,19 +50,19 @@ KDCoordinate EmptyLayoutNode::computeBaseline() { return (m_margins ? k_marginHeight : 0) + height()/2; } -void EmptyLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void EmptyLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { /* The two cursor positions around an EmptyLayoutNode are equivalent, so both * should be checked. */ assert(cursor->layoutNode() == this); LayoutCursor cursorResult = cursor->clone(); - LayoutNode::moveCursorVertically(direction, &cursorResult, shouldRecomputeLayout, equivalentPositionVisited); + LayoutNode::moveCursorVertically(direction, &cursorResult, shouldRecomputeLayout, equivalentPositionVisited, forSelection); if (cursorResult.isDefined()) { cursor->setTo(&cursorResult); return; } LayoutCursor::Position newPosition = cursor->position() == LayoutCursor::Position::Left ? LayoutCursor::Position::Right : LayoutCursor::Position::Left; cursor->setPosition(newPosition); - LayoutNode::moveCursorVertically(direction, cursor, shouldRecomputeLayout, false); + LayoutNode::moveCursorVertically(direction, cursor, shouldRecomputeLayout, false, forSelection); } bool EmptyLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode * sibling, bool moveCursor) { diff --git a/poincare/src/fraction_layout.cpp b/poincare/src/fraction_layout.cpp index 3a7cb32d2..7946e9041 100644 --- a/poincare/src/fraction_layout.cpp +++ b/poincare/src/fraction_layout.cpp @@ -10,7 +10,7 @@ namespace Poincare { static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } -void FractionLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void FractionLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Left && (cursor->layoutNode() == numeratorLayout() || cursor->layoutNode() == denominatorLayout())) @@ -34,7 +34,7 @@ void FractionLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco } } -void FractionLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void FractionLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->position() == LayoutCursor::Position::Right && (cursor->layoutNode() == numeratorLayout() || cursor->layoutNode() == denominatorLayout())) @@ -57,7 +57,7 @@ void FractionLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec } } -void FractionLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void FractionLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(denominatorLayout(), true)) { // If the cursor is inside denominator, move it to the numerator. numeratorLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout); @@ -71,7 +71,7 @@ void FractionLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomp LayoutNode::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -void FractionLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void FractionLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(numeratorLayout(), true)) { // If the cursor is inside numerator, move it to the denominator. denominatorLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout); diff --git a/poincare/src/grid_layout.cpp b/poincare/src/grid_layout.cpp index f41270699..f09097d7b 100644 --- a/poincare/src/grid_layout.cpp +++ b/poincare/src/grid_layout.cpp @@ -8,7 +8,7 @@ static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { retur // LayoutNode -void GridLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void GridLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == this && cursor->position() == LayoutCursor::Position::Right) { // Case: Right. Go to the last entry. cursor->setLayoutNode(childAtIndex(numberOfChildren() - 1)); @@ -36,7 +36,7 @@ void GridLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomput } } -void GridLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void GridLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == this && cursor->position() == LayoutCursor::Position::Left) { // Case: Left. Go to the first entry. assert(numberOfChildren() >= 1); @@ -65,7 +65,7 @@ void GridLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecompu } } -void GridLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void GridLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { /* If the cursor is child that is not on the top row, move it inside its upper * neighbour. */ int childIndex = m_numberOfColumns; @@ -79,7 +79,7 @@ void GridLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeL LayoutNode::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -void GridLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void GridLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { int childIndex = 0; int maxIndex = numberOfChildren() - m_numberOfColumns; for (LayoutNode * l : children()) { diff --git a/poincare/src/horizontal_layout.cpp b/poincare/src/horizontal_layout.cpp index bbb355bdf..88fb0bafd 100644 --- a/poincare/src/horizontal_layout.cpp +++ b/poincare/src/horizontal_layout.cpp @@ -10,7 +10,7 @@ static inline KDCoordinate maxCoordinate(KDCoordinate c1, KDCoordinate c2) { ret // LayoutNode -void HorizontalLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void HorizontalLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (this == cursor->layoutNode()) { if (cursor->position() == LayoutCursor::Position::Left) { // Case: Left. Ask the parent. @@ -50,7 +50,7 @@ void HorizontalLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRe cursor->moveLeft(shouldRecomputeLayout); } -void HorizontalLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void HorizontalLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (this == cursor->layoutNode()) { if (cursor->position() == LayoutCursor::Position::Right) { // Case: Right. Ask the parent. diff --git a/poincare/src/integral_layout.cpp b/poincare/src/integral_layout.cpp index 2927d97ab..ca5416202 100644 --- a/poincare/src/integral_layout.cpp +++ b/poincare/src/integral_layout.cpp @@ -23,7 +23,7 @@ const uint8_t bottomSymbolPixel[IntegralLayoutNode::k_symbolHeight][IntegralLayo {0xFF, 0xFF, 0x00, 0x00}, }; -void IntegralLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void IntegralLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == upperBoundLayout() || cursor->layoutNode() == lowerBoundLayout()) { @@ -63,7 +63,7 @@ void IntegralLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco } } -void IntegralLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void IntegralLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == upperBoundLayout() || cursor->layoutNode() == lowerBoundLayout()) { @@ -104,7 +104,7 @@ void IntegralLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec } } -void IntegralLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void IntegralLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(lowerBoundLayout(), true)) { // If the cursor is inside the lower bound, move it to the upper bound. upperBoundLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout); @@ -118,7 +118,7 @@ void IntegralLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomp LayoutNode::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -void IntegralLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void IntegralLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(upperBoundLayout(), true)) { // If the cursor is inside the upper bound, move it to the lower bound. lowerBoundLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout); diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index e65797b15..61e2a0c30 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -58,20 +58,25 @@ KDPoint LayoutCursor::middleLeftPoint() { } /* Move */ -void LayoutCursor::move(Direction direction, bool * shouldRecomputeLayout) { +void LayoutCursor::move(Direction direction, bool * shouldRecomputeLayout, bool forSelection) { if (direction == Direction::Left) { - moveLeft(shouldRecomputeLayout); + moveLeft(shouldRecomputeLayout, forSelection); } else if (direction == Direction::Right) { - moveRight(shouldRecomputeLayout); + moveRight(shouldRecomputeLayout, forSelection); } else if (direction == Direction::Up) { - moveAbove(shouldRecomputeLayout); - } else if (direction == Direction::Down) { - moveUnder(shouldRecomputeLayout); + moveAbove(shouldRecomputeLayout, forSelection); } else { - assert(false); + assert(direction == Direction::Down); + moveUnder(shouldRecomputeLayout, forSelection); } } +LayoutCursor LayoutCursor::cursorAtDirection(Direction direction, bool * shouldRecomputeLayout, bool forSelection) { + LayoutCursor result = clone(); + result.move(direction, shouldRecomputeLayout, forSelection); + return result; +} + /* Select */ void LayoutCursor::select(Direction direction, bool * shouldRecomputeLayout, Layout * selection) { @@ -360,7 +365,7 @@ void LayoutCursor::selectLeftRight(bool right, bool * shouldRecomputeLayout, Lay void LayoutCursor::selectUpDown(bool up, bool * shouldRecomputeLayout, Layout * selection) { // Move the cursor in the selection direction - LayoutCursor c = cursorAtDirection(up ? Direction::Up : Direction::Down, shouldRecomputeLayout); + LayoutCursor c = cursorAtDirection(up ? Direction::Up : Direction::Down, shouldRecomputeLayout, true); if (!c.isDefined()) { return; } diff --git a/poincare/src/layout_node.cpp b/poincare/src/layout_node.cpp index d53aaaa5c..c1ece351f 100644 --- a/poincare/src/layout_node.cpp +++ b/poincare/src/layout_node.cpp @@ -169,7 +169,7 @@ bool LayoutNode::protectedIsIdenticalTo(Layout l) { return true; } -void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (!equivalentPositionVisited) { LayoutCursor cursorEquivalent = equivalentCursor(cursor); if (cursorEquivalent.isDefined()) { @@ -195,7 +195,7 @@ void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor } } -void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { LayoutNode * childResult = nullptr; LayoutNode ** childResultPtr = &childResult; LayoutCursor::Position resultPosition = LayoutCursor::Position::Left; @@ -203,7 +203,7 @@ void LayoutNode::moveCursorInDescendantsVertically(VerticalDirection direction, * than this initial value of score. */ int resultScore = Ion::Display::Width*Ion::Display::Width + Ion::Display::Height*Ion::Display::Height; - scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResultPtr, &resultPosition, &resultScore); + scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResultPtr, &resultPosition, &resultScore, forSelection); // If there is a valid result Layout resultRef(childResult); @@ -221,7 +221,8 @@ void LayoutNode::scoreCursorInDescendantsVertically ( bool * shouldRecomputeLayout, LayoutNode ** childResult, void * resultPosition, - int * resultScore) + int * resultScore, + bool forSelection) { LayoutCursor::Position * castedResultPosition = static_cast(resultPosition); KDPoint cursorMiddleLeft = cursor->middleLeftPoint(); @@ -247,7 +248,7 @@ void LayoutNode::scoreCursorInDescendantsVertically ( } if (layoutIsUnderOrAbove || layoutContains) { for (LayoutNode * c : children()) { - c->scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResult, castedResultPosition, resultScore); + c->scoreCursorInDescendantsVertically(direction, cursor, shouldRecomputeLayout, childResult, castedResultPosition, resultScore, forSelection); } } } diff --git a/poincare/src/matrix_layout.cpp b/poincare/src/matrix_layout.cpp index 921afea40..a82ac00af 100644 --- a/poincare/src/matrix_layout.cpp +++ b/poincare/src/matrix_layout.cpp @@ -28,7 +28,7 @@ void MatrixLayoutNode::removeGreySquares() { // LayoutNode -void MatrixLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void MatrixLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { int childIndex = indexOfChild(cursor->layoutNode()); if (childIndex >= 0 && cursor->position() == LayoutCursor::Position::Left @@ -54,10 +54,10 @@ void MatrixLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomp cursor->setLayoutNode(lastChild); return; } - GridLayoutNode::moveCursorLeft(cursor, shouldRecomputeLayout); + GridLayoutNode::moveCursorLeft(cursor, shouldRecomputeLayout, forSelection); } -void MatrixLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void MatrixLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == this && cursor->position() == LayoutCursor::Position::Left) { @@ -83,7 +83,7 @@ void MatrixLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecom return; } - GridLayoutNode::moveCursorRight(cursor, shouldRecomputeLayout); + GridLayoutNode::moveCursorRight(cursor, shouldRecomputeLayout, forSelection); } void MatrixLayoutNode::willAddSiblingToEmptyChildAtIndex(int childIndex) { @@ -182,7 +182,7 @@ KDPoint MatrixLayoutNode::positionOfChild(LayoutNode * l) { return GridLayoutNode::positionOfChild(l).translatedBy(KDPoint(KDPoint(SquareBracketLayoutNode::BracketWidth(), SquareBracketLayoutNode::k_lineThickness))); } -void MatrixLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void MatrixLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { MatrixLayout thisRef = MatrixLayout(this); bool shouldRemoveGreySquares = false; int firstIndex = direction == VerticalDirection::Up ? 0 : numberOfChildren() - m_numberOfColumns; @@ -199,7 +199,7 @@ void MatrixLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutC } i++; } - GridLayoutNode::moveCursorVertically(direction, cursor, shouldRecomputeLayout, equivalentPositionVisited); + GridLayoutNode::moveCursorVertically(direction, cursor, shouldRecomputeLayout, equivalentPositionVisited, forSelection); if (cursor->isDefined() && shouldRemoveGreySquares) { assert(thisRef.hasGreySquares()); thisRef.removeGreySquares(); diff --git a/poincare/src/nth_root_layout.cpp b/poincare/src/nth_root_layout.cpp index 06e5480f4..807c15449 100644 --- a/poincare/src/nth_root_layout.cpp +++ b/poincare/src/nth_root_layout.cpp @@ -32,7 +32,7 @@ bool NthRootLayoutNode::isSquareRoot() const { return false; } -void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == radicandLayout() && cursor->position() == LayoutCursor::Position::Left) { @@ -67,7 +67,7 @@ void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecom } } -void NthRootLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void NthRootLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == radicandLayout() && cursor->position() == LayoutCursor::Position::Right) { @@ -102,7 +102,7 @@ void NthRootLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldReco } } -void NthRootLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void NthRootLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (indexLayout() != nullptr && cursor->isEquivalentTo(LayoutCursor(radicandLayout(), LayoutCursor::Position::Left))) { @@ -123,7 +123,7 @@ void NthRootLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecompu LayoutNode::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -void NthRootLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void NthRootLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (indexLayout() != nullptr && cursor->layoutNode()->hasAncestor(indexLayout(), true)) { diff --git a/poincare/src/sequence_layout.cpp b/poincare/src/sequence_layout.cpp index 0e8593deb..9ada97de5 100644 --- a/poincare/src/sequence_layout.cpp +++ b/poincare/src/sequence_layout.cpp @@ -9,7 +9,7 @@ namespace Poincare { static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } -void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == upperBoundLayout()) { assert(cursor->position() == LayoutCursor::Position::Left); @@ -55,7 +55,7 @@ void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco } } -void SequenceLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void SequenceLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == lowerBoundLayout() || cursor->layoutNode() == upperBoundLayout()) { @@ -94,7 +94,7 @@ void SequenceLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec } } -void SequenceLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void SequenceLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(lowerBoundLayout(), true) || cursor->layoutNode()->hasAncestor(variableLayout(), true)) { // If the cursor is inside the lower bound or inside the variable name, move it to the upper bound upperBoundLayout()->moveCursorUpInDescendants(cursor, shouldRecomputeLayout); @@ -114,7 +114,7 @@ void SequenceLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomp LayoutNode::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -void SequenceLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void SequenceLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (cursor->layoutNode()->hasAncestor(upperBoundLayout(), true)) { // If the cursor is inside the upper bound, move it to the lower bound lowerBoundLayout()->moveCursorDownInDescendants(cursor, shouldRecomputeLayout); diff --git a/poincare/src/vertical_offset_layout.cpp b/poincare/src/vertical_offset_layout.cpp index 35aec2303..aa066246f 100644 --- a/poincare/src/vertical_offset_layout.cpp +++ b/poincare/src/vertical_offset_layout.cpp @@ -10,7 +10,7 @@ namespace Poincare { static inline int minInt(int x, int y) { return x < y ? x : y; } -void VerticalOffsetLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void VerticalOffsetLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == indiceLayout() && cursor->position() == LayoutCursor::Position::Left) { @@ -33,7 +33,7 @@ void VerticalOffsetLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shou } } -void VerticalOffsetLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { +void VerticalOffsetLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool forSelection) { if (cursor->layoutNode() == indiceLayout() && cursor->position() == LayoutCursor::Position::Right) { @@ -55,7 +55,7 @@ void VerticalOffsetLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * sho } } -void VerticalOffsetLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void VerticalOffsetLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (m_position == Position::Superscript) { // Case: Superscript. if (cursor->isEquivalentTo(LayoutCursor(this, LayoutCursor::Position::Right))) { @@ -83,7 +83,7 @@ void VerticalOffsetLayoutNode::moveCursorUp(LayoutCursor * cursor, bool * should LayoutNode::moveCursorUp(cursor, shouldRecomputeLayout, equivalentPositionVisited); } -void VerticalOffsetLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) { +void VerticalOffsetLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited, bool forSelection) { if (m_position == Position::Subscript) { // Case: Subscript. if (cursor->isEquivalentTo(LayoutCursor(this, LayoutCursor::Position::Right))) {