From 05c479a6fcd59762e6fab619ca1d554aff0f8552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 24 Jun 2019 16:43:40 +0200 Subject: [PATCH] [poincare] Better collapsing of fractions The user can now write intuitively 1/2 * 3/4 --- poincare/src/code_point_layout.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/poincare/src/code_point_layout.cpp b/poincare/src/code_point_layout.cpp index 4d08a014c..9d8a01fb6 100644 --- a/poincare/src/code_point_layout.cpp +++ b/poincare/src/code_point_layout.cpp @@ -59,6 +59,24 @@ bool CodePointLayoutNode::isCollapsable(int * numberOfOpenParenthesis, bool goin return false; } } + if (isMultiplicationCodePoint()) { + /* We want '*' to be collapsable only if the following brother is not a + * fraction, so that the user can write intuitively "1/2 * 3/4". */ + Layout thisRef = CodePointLayout(this); + Layout parent = thisRef.parent(); + if (!parent.isUninitialized()) { + int indexOfThis = parent.indexOfChild(thisRef); + Layout brother; + if (indexOfThis > 0 && goingLeft) { + brother = parent.childAtIndex(indexOfThis-1); + } else if (indexOfThis < parent.numberOfChildren() - 1 && !goingLeft) { + brother = parent.childAtIndex(indexOfThis+1); + } + if (!brother.isUninitialized() && brother.type() == LayoutNode::Type::FractionLayout) { + return false; + } + } + } return true; }