From 323e72a50ca5253bdbe1d772f7ecd479de4402b9 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 12 Nov 2020 12:21:06 +0100 Subject: [PATCH] [poincare/matrix_layout] Remove columns with backspace Allow removing empty columns with backspace, the same way one can remove empty rows. This allows deleting the internal columns that are not automatically deleted. Change-Id: I52def7939257942a8396721d01c4d1531ef90361 --- poincare/src/matrix_layout.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/poincare/src/matrix_layout.cpp b/poincare/src/matrix_layout.cpp index 9300ac148..c57af6126 100644 --- a/poincare/src/matrix_layout.cpp +++ b/poincare/src/matrix_layout.cpp @@ -92,20 +92,32 @@ void MatrixLayoutNode::willAddSiblingToEmptyChildAtIndex(int childIndex) { } void MatrixLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { - // Deleting the left empty layout of an empty row deletes the row + /* Deleting the left empty layout of an empty row deletes the row, and + * deleting the top empty layout of an empty column deletes the column. */ assert(cursor != nullptr); LayoutNode * pointedChild = cursor->layoutNode(); if (pointedChild->isEmpty()) { int indexOfPointedLayout = indexOfChild(pointedChild); - if (columnAtChildIndex(indexOfPointedLayout) == 0) { - int rowIndex = rowAtChildIndex(indexOfPointedLayout); + int columnIndex = columnAtChildIndex(indexOfPointedLayout); + int rowIndex = rowAtChildIndex(indexOfPointedLayout); + bool deleted = false; + if (columnIndex == 0) { if (rowIndex < m_numberOfRows - 1 && isRowEmpty(rowIndex) && m_numberOfRows > 2) { deleteRowAtIndex(rowIndex); + deleted = true; + } + } + if (rowIndex == 0) { + if (columnIndex < m_numberOfColumns - 1 && isColumnEmpty(columnIndex) && m_numberOfColumns > 2) { + deleteColumnAtIndex(columnIndex); + deleted = true; + } + } + if (deleted) { assert(indexOfPointedLayout >= 0 && indexOfPointedLayout < m_numberOfColumns*m_numberOfRows); cursor->setLayoutNode(childAtIndex(indexOfPointedLayout)); cursor->setPosition(LayoutCursor::Position::Right); return; - } } } GridLayoutNode::deleteBeforeCursor(cursor);