From 3abb619283cfa58cd41e66d682b88ccbd3e9f9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 17 Apr 2018 10:06:14 +0200 Subject: [PATCH] [poincare] Hiding/Show EmptyLayouts: check pointed layout's neighbour Change-Id: I5f6977de5c14e409b40f7f371d5dfa390f2dca37 --- poincare/src/expression_layout_cursor.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/poincare/src/expression_layout_cursor.cpp b/poincare/src/expression_layout_cursor.cpp index 418fc85f3..a1763ed02 100644 --- a/poincare/src/expression_layout_cursor.cpp +++ b/poincare/src/expression_layout_cursor.cpp @@ -221,13 +221,36 @@ bool ExpressionLayoutCursor::hideEmptyLayoutIfNeeded() { } bool ExpressionLayoutCursor::privateShowHideEmptyLayoutIfNeeded(bool show) { + /* Find Empty layouts adjacent to the cursor: Check the pointed layout and its + * neighbour in an Horizontal layout */ + + // Check the pointed layout if (m_pointedExpressionLayout->isEmpty()) { + /* An empty layout is either an EmptyLayout or an HorizontalLayout with one + * child only, and this child is an EmptyLayout. */ if (m_pointedExpressionLayout->isHorizontal()) { static_cast(m_pointedExpressionLayout->editableChild(0))->setVisible(show); } else { static_cast(m_pointedExpressionLayout)->setVisible(show); } return true; + } else if (m_pointedExpressionLayout->parent() != nullptr + && m_pointedExpressionLayout->parent()->isHorizontal()) + { + // Check the neighbour of the pointed layout in an HorizontalLayout + int indexInParent = m_pointedExpressionLayout->parent()->indexOfChild(m_pointedExpressionLayout); + int indexToCheck = m_position == Position::Right ? indexInParent + 1 : indexInParent - 1; + if (indexToCheck >=0 + && indexToCheck < m_pointedExpressionLayout->parent()->numberOfChildren() + && m_pointedExpressionLayout->parent()->child(indexToCheck)->isEmpty()) + { + if (m_pointedExpressionLayout->isHorizontal()) { + static_cast(m_pointedExpressionLayout->editableParent()->editableChild(indexToCheck)->editableChild(0))->setVisible(show); + } else { + static_cast(m_pointedExpressionLayout->editableParent()->editableChild(indexToCheck))->setVisible(show); + } + return true; + } } return false; }