[escher] Moved repetition factor logic up in Escher from poincare

Change-Id: I7c8f932e3e7d04c928ca881113ba6b5df05b94e7
This commit is contained in:
Hugo Saint-Vignes
2020-11-27 14:55:06 +01:00
committed by LeaNumworks
parent b69f06b772
commit 636e863323
3 changed files with 17 additions and 38 deletions

View File

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

View File

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

View File

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