From 70cd166da53259271961f2ce4659caaa87e38d5e Mon Sep 17 00:00:00 2001 From: Hugo Saint-Vignes Date: Wed, 10 Jun 2020 14:06:14 +0200 Subject: [PATCH] [escher] Scroll speed increase for long repetition in layout fields Change-Id: I9460cb44631f0b225598804334da5a0e74029915 --- escher/src/layout_field.cpp | 7 ++- poincare/include/poincare/layout_cursor.h | 8 +--- poincare/src/layout_cursor.cpp | 53 ++++++++++++++++++++++- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index 4a8a58197..870a6c332 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -591,7 +591,8 @@ bool LayoutField::privateHandleMoveEvent(Ion::Events::Event event, bool * should return true; } LayoutCursor result; - result = m_contentView.cursor()->cursorAtDirection(DirectionForMoveEvent(event), shouldRecomputeLayout); + int step = Ion::Events::longRepetitionScrollSpeed(); + result = m_contentView.cursor()->cursorAtDirection(DirectionForMoveEvent(event), shouldRecomputeLayout, false, step); if (result.isDefined()) { if (eventShouldUpdateInsertionCursor(event)) { m_contentView.updateInsertionCursor(); @@ -628,10 +629,12 @@ bool LayoutField::privateHandleSelectionEvent(Ion::Events::Event event, bool * s return false; } Layout addedSelection; + int step = Ion::Events::longRepetitionScrollSpeed(); LayoutCursor result = m_contentView.cursor()->selectAtDirection( DirectionForSelectionEvent(event), shouldRecomputeLayout, - &addedSelection + &addedSelection, + step ); if (addedSelection.isUninitialized()) { return false; diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index 8979d7b53..c4ec2885d 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -95,15 +95,11 @@ public: void moveUnder(bool * shouldRecomputeLayout, bool forSelection = false) { layoutNode()->moveCursorDown(this, shouldRecomputeLayout, false, forSelection); } - LayoutCursor cursorAtDirection(Direction direction, bool * shouldRecomputeLayout, bool forSelection = false); + LayoutCursor cursorAtDirection(Direction direction, bool * shouldRecomputeLayout, bool forSelection = false, int step = 1); /* Select */ void select(Direction direction, bool * shouldRecomputeLayout, Layout * selection); - LayoutCursor selectAtDirection(Direction direction, bool * shouldRecomputeLayout, Layout * selection) { - LayoutCursor result = clone(); - result.select(direction, shouldRecomputeLayout, selection); - return result; - } + LayoutCursor selectAtDirection(Direction direction, bool * shouldRecomputeLayout, Layout * selection, int step = 1); /* Layout modification */ void addEmptyExponentialLayout(); diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index 33096cc57..a8998f6d4 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -69,9 +69,30 @@ void LayoutCursor::move(Direction direction, bool * shouldRecomputeLayout, bool } } -LayoutCursor LayoutCursor::cursorAtDirection(Direction direction, bool * shouldRecomputeLayout, bool forSelection) { +LayoutCursor LayoutCursor::cursorAtDirection(Direction direction, bool * shouldRecomputeLayout, bool forSelection, int step) { LayoutCursor result = clone(); + if (step <= 0) { + return result; + } + // First step result.move(direction, shouldRecomputeLayout, forSelection); + + if (step == 1 || !result.isDefined()) { + // If first step is undefined, it is returned so the situation is handled + return result; + } + // Otherwise, as many steps as possible are performed + LayoutCursor result_temp = result; + for (int i = 1; i < step; ++i) { + result_temp.move(direction, shouldRecomputeLayout, forSelection); + if (!result_temp.isDefined()) { + // Return last successful result + return result; + } + // Update last successful result + result = result_temp; + assert(result.isDefined()); + } return result; } @@ -85,6 +106,36 @@ void LayoutCursor::select(Direction direction, bool * shouldRecomputeLayout, Lay } } +LayoutCursor LayoutCursor::selectAtDirection(Direction direction, bool * shouldRecomputeLayout, Layout * selection, int step) { + 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; +} + /* Layout modification */ void LayoutCursor::addEmptyExponentialLayout() {