diff --git a/escher/include/escher/layout_field.h b/escher/include/escher/layout_field.h index d8c4694b1..b2ebf927c 100644 --- a/escher/include/escher/layout_field.h +++ b/escher/include/escher/layout_field.h @@ -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); diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index 73b394c28..86fd6aa1e 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -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(event) <= static_cast(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)) {