From 636e8633235d6db7a1942546157b6d7262e8a682 Mon Sep 17 00:00:00 2001 From: Hugo Saint-Vignes Date: Fri, 27 Nov 2020 14:55:06 +0100 Subject: [PATCH] [escher] Moved repetition factor logic up in Escher from poincare Change-Id: I7c8f932e3e7d04c928ca881113ba6b5df05b94e7 --- escher/src/layout_field.cpp | 27 +++++++++++++---------- poincare/include/poincare/layout_cursor.h | 2 +- poincare/src/layout_cursor.cpp | 26 +--------------------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index a4c4c3a07..acc4256c1 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -641,20 +641,23 @@ bool LayoutField::privateHandleSelectionEvent(Ion::Events::Event event, bool * s if (!IsSelectionEvent(event)) { return false; } - Layout addedSelection; int step = Ion::Events::repetitionFactor(); - LayoutCursor result = m_contentView.cursor()->selectAtDirection( - DirectionForSelectionEvent(event), - shouldRecomputeLayout, - &addedSelection, - step - ); - if (addedSelection.isUninitialized()) { - return false; + // Selection is handled one step at a time. Repeat selection for each step. + for (int i = 0; i < step; ++i) { + Layout addedSelection; + LayoutCursor result = m_contentView.cursor()->selectAtDirection( + DirectionForSelectionEvent(event), + shouldRecomputeLayout, + &addedSelection + ); + if (addedSelection.isUninitialized()) { + // Successful event if at least one step succeeded. + return i > 0; + } + m_contentView.addSelection(addedSelection); + assert(result.isDefined()); + m_contentView.setCursor(result); } - m_contentView.addSelection(addedSelection); - assert(result.isDefined()); - m_contentView.setCursor(result); return true; } diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index c4ec2885d..3569aa0f6 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -99,7 +99,7 @@ public: /* Select */ void select(Direction direction, bool * shouldRecomputeLayout, Layout * selection); - LayoutCursor selectAtDirection(Direction direction, bool * shouldRecomputeLayout, Layout * selection, int step = 1); + LayoutCursor selectAtDirection(Direction direction, bool * shouldRecomputeLayout, Layout * selection); /* Layout modification */ void addEmptyExponentialLayout(); diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index b90c6922e..78a7491e6 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -106,33 +106,9 @@ void LayoutCursor::select(Direction direction, bool * shouldRecomputeLayout, Lay } } -LayoutCursor LayoutCursor::selectAtDirection(Direction direction, bool * shouldRecomputeLayout, Layout * selection, int step) { +LayoutCursor LayoutCursor::selectAtDirection(Direction direction, bool * shouldRecomputeLayout, Layout * selection) { LayoutCursor result = clone(); - if (step <= 0) { - return result; - } - // First step result.select(direction, shouldRecomputeLayout, selection); - - if (step == 1 || selection->isUninitialized()) { - // If first step failed, result is returned so the situation is handled - return result; - } - // Otherwise, as many steps as possible are performed - // Shallow copy to temporary variables - LayoutCursor result_temp = result; - Layout selection_temp = *selection; - for (int i = 1; i < step; ++i) { - result_temp.select(direction, shouldRecomputeLayout, &selection_temp); - if (selection_temp.isUninitialized()) { - // Return last successful result - return result; - } - // Update last successful result - result = result_temp; - *selection = selection_temp; - assert(result.isDefined()); - } return result; }