[poincare] Move the cursor when collapsing a layout

Change-Id: I28a80ac19310214044bad653a6f887956d1fdacc
This commit is contained in:
Léa Saviot
2018-04-17 12:26:19 +02:00
parent 9f0755a330
commit 42e15d6a15
7 changed files with 16 additions and 12 deletions

View File

@@ -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; }

View File

@@ -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() {

View File

@@ -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);
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -25,8 +25,10 @@ ExpressionLayout * NthRootLayout::clone() const {
return new NthRootLayout(const_cast<NthRootLayout *>(this)->radicandLayout(), const_cast<NthRootLayout *>(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) {

View File

@@ -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 */