From e03bb7432e7fb5ad732390b205c16331debc044e Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Tue, 16 Jun 2020 16:11:05 +0200 Subject: [PATCH] [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 --- escher/include/escher/layout_field.h | 2 +- escher/src/layout_field.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) 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)) {