[escher] Scroll speed increase for long repetition in layout fields

Change-Id: I9460cb44631f0b225598804334da5a0e74029915
This commit is contained in:
Hugo Saint-Vignes
2020-06-10 14:06:14 +02:00
committed by Émilie Feral
parent 70830e0b74
commit 70cd166da5
3 changed files with 59 additions and 9 deletions

View File

@@ -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;

View File

@@ -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();

View File

@@ -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() {