[escher] Tweaked LayoutField event handling

LayoutField does no redraw its content on every occasion anymore. This
allows the input window in Calculation to not scroll to the beginning
when writing an overly long formula.

Change-Id: I14276828884035463b0a6438bfca4dd76c7f5057
This commit is contained in:
Gabriel Ozouf
2020-06-16 16:11:05 +02:00
committed by Émilie Feral
parent 41cf0aaac6
commit e03bb7432e
2 changed files with 11 additions and 3 deletions

View File

@@ -56,7 +56,7 @@ private:
constexpr static int k_maxNumberOfLayouts = 220;
static_assert(k_maxNumberOfLayouts == TextField::maxBufferSize(), "Maximal number of layouts in a layout field should be equal to max number of char in text field");
void reload(KDSize previousSize);
virtual bool privateHandleEvent(Ion::Events::Event event);
virtual bool privateHandleEvent(Ion::Events::Event event, bool * shouldScrollAndRedraw);
bool privateHandleMoveEvent(Ion::Events::Event event, bool * shouldRecomputeLayout);
bool privateHandleSelectionEvent(Ion::Events::Event event, bool * shouldRecomputeLayout);
void scrollRightOfLayout(Poincare::Layout layoutR);

View File

@@ -421,6 +421,7 @@ bool LayoutField::handleEvent(Ion::Events::Event event) {
if (!eventShouldUpdateInsertionCursor(event)) {
m_contentView.invalidateInsertionCursor();
}
bool shouldScrollAndRedraw = true;
if (privateHandleMoveEvent(event, &moveEventChangedLayout)) {
if (!isEditing()) {
setEditing(true);
@@ -444,7 +445,12 @@ bool LayoutField::handleEvent(Ion::Events::Event event) {
}
shouldRecomputeLayout = m_contentView.cursor()->layout().removeGreySquaresFromAllMatrixChildren() || removedSquares || shouldRecomputeLayout;
}
} else if (privateHandleEvent(event)) {
} else if (privateHandleEvent(event, &shouldScrollAndRedraw)) {
if (!shouldScrollAndRedraw) {
/* We escape early to avoid scrolling to the beginning of the expression,
* and to mimic the behaviour of the TextField. */
return true;
}
shouldRecomputeLayout = true;
didHandleEvent = true;
}
@@ -492,8 +498,10 @@ static inline bool IsMoveEvent(Ion::Events::Event event) {
static_cast<uint8_t>(event) <= static_cast<uint8_t>(Ion::Events::Right);
}
bool LayoutField::privateHandleEvent(Ion::Events::Event event) {
bool LayoutField::privateHandleEvent(Ion::Events::Event event, bool * shouldScrollAndRedraw) {
assert(*shouldScrollAndRedraw);
if (m_delegate && m_delegate->layoutFieldDidReceiveEvent(this, event)) {
*shouldScrollAndRedraw = false;
return true;
}
if (handleBoxEvent(event)) {