diff --git a/poincare/include/poincare/expression_layout.h b/poincare/include/poincare/expression_layout.h index 5ed835743..1064f7488 100644 --- a/poincare/include/poincare/expression_layout.h +++ b/poincare/include/poincare/expression_layout.h @@ -50,7 +50,7 @@ public: /* Dynamic Layout */ // Collapse - virtual void collapseBrothers() {} + virtual void collapseBrothersAndMoveCursor(ExpressionLayoutCursor * cursor); // Add virtual bool addChildAtIndex(ExpressionLayout * child, int index) { return false; } diff --git a/poincare/src/expression_layout_cursor.cpp b/poincare/src/expression_layout_cursor.cpp index 45e71ca10..a5e33e4e1 100644 --- a/poincare/src/expression_layout_cursor.cpp +++ b/poincare/src/expression_layout_cursor.cpp @@ -64,10 +64,7 @@ void ExpressionLayoutCursor::addFractionLayoutAndCollapseBrothers() { HorizontalLayout * child2 = new HorizontalLayout(new EmptyLayout(), false); FractionLayout * newChild = new FractionLayout(child1, child2, false); pointedExpressionLayout()->addBrother(this, newChild); - newChild->collapseBrothers(); - // Set the cursor position - setPointedExpressionLayout(child2->editableChild(0)); - setPosition(Position::Left); + newChild->collapseBrothersAndMoveCursor(this); } void ExpressionLayoutCursor::addEmptyMatrixLayout(int numberOfRows, int numberOfColumns) { @@ -110,9 +107,7 @@ void ExpressionLayoutCursor::addEmptySquareRootLayout() { HorizontalLayout * child1 = new HorizontalLayout(new EmptyLayout(), false); NthRootLayout * newChild = new NthRootLayout(child1, false); m_pointedExpressionLayout->addBrother(this, newChild); - newChild->collapseBrothers(); - setPointedExpressionLayout(child1); - setPosition(ExpressionLayoutCursor::Position::Left); + newChild->collapseBrothersAndMoveCursor(this); } void ExpressionLayoutCursor::addEmptySquarePowerLayout() { diff --git a/poincare/src/layout/expression_layout.cpp b/poincare/src/layout/expression_layout.cpp index 8ab2ae2b3..119631668 100644 --- a/poincare/src/layout/expression_layout.cpp +++ b/poincare/src/layout/expression_layout.cpp @@ -105,6 +105,11 @@ bool ExpressionLayout::hasAncestor(const ExpressionLayout * e) const { return m_parent->hasAncestor(e); } +void ExpressionLayout::collapseBrothersAndMoveCursor(ExpressionLayoutCursor * cursor) { + cursor->setPointedExpressionLayout(this); + cursor->setPosition(ExpressionLayoutCursor::Position::Right); +} + void ExpressionLayout::addBrother(ExpressionLayoutCursor * cursor, ExpressionLayout * brother) { privateAddBrother(cursor, brother, false); } diff --git a/poincare/src/layout/fraction_layout.cpp b/poincare/src/layout/fraction_layout.cpp index 3324f7ecd..659da4265 100644 --- a/poincare/src/layout/fraction_layout.cpp +++ b/poincare/src/layout/fraction_layout.cpp @@ -14,9 +14,11 @@ ExpressionLayout * FractionLayout::clone() const { return layout; } -void FractionLayout::collapseBrothers() { +void FractionLayout::collapseBrothersAndMoveCursor(ExpressionLayoutCursor * cursor) { ExpressionLayout::collapseOnDirection(HorizontalDirection::Right, 1); ExpressionLayout::collapseOnDirection(HorizontalDirection::Left, 0); + cursor->setPointedExpressionLayout(denominatorLayout()); + cursor->setPosition(ExpressionLayoutCursor::Position::Left); } void FractionLayout::backspaceAtCursor(ExpressionLayoutCursor * cursor) { diff --git a/poincare/src/layout/fraction_layout.h b/poincare/src/layout/fraction_layout.h index 9491fb81a..65ab4251f 100644 --- a/poincare/src/layout/fraction_layout.h +++ b/poincare/src/layout/fraction_layout.h @@ -10,7 +10,7 @@ class FractionLayout : public StaticLayoutHierarchy<2> { public: using StaticLayoutHierarchy::StaticLayoutHierarchy; ExpressionLayout * clone() const override; - void collapseBrothers() override; + void collapseBrothersAndMoveCursor(ExpressionLayoutCursor * cursor) override; void backspaceAtCursor(ExpressionLayoutCursor * cursor) override; bool moveLeft(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; bool moveRight(ExpressionLayoutCursor * cursor, bool * shouldRecomputeLayout) override; diff --git a/poincare/src/layout/nth_root_layout.cpp b/poincare/src/layout/nth_root_layout.cpp index 8b270cb1b..2eddf12d6 100644 --- a/poincare/src/layout/nth_root_layout.cpp +++ b/poincare/src/layout/nth_root_layout.cpp @@ -25,8 +25,10 @@ ExpressionLayout * NthRootLayout::clone() const { return new NthRootLayout(const_cast(this)->radicandLayout(), const_cast(this)->indexLayout(), true); } -void NthRootLayout::collapseBrothers() { +void NthRootLayout::collapseBrothersAndMoveCursor(ExpressionLayoutCursor * cursor) { ExpressionLayout::collapseOnDirection(HorizontalDirection::Right, 0); + cursor->setPointedExpressionLayout(radicandLayout()); + cursor->setPosition(ExpressionLayoutCursor::Position::Left); } void NthRootLayout::backspaceAtCursor(ExpressionLayoutCursor * cursor) { diff --git a/poincare/src/layout/nth_root_layout.h b/poincare/src/layout/nth_root_layout.h index c8a15dc9e..f5d31c723 100644 --- a/poincare/src/layout/nth_root_layout.h +++ b/poincare/src/layout/nth_root_layout.h @@ -14,7 +14,7 @@ public: ExpressionLayout * clone() const override; /* Dynamic Layout*/ - void collapseBrothers() override; + void collapseBrothersAndMoveCursor(ExpressionLayoutCursor * cursor) override; void backspaceAtCursor(ExpressionLayoutCursor * cursor) override; /* Tree navigation */