diff --git a/escher/include/escher/layout_field.h b/escher/include/escher/layout_field.h index ef19f271a..1fefd2688 100644 --- a/escher/include/escher/layout_field.h +++ b/escher/include/escher/layout_field.h @@ -21,7 +21,7 @@ public: {} void setDelegates(InputEventHandlerDelegate * inputEventHandlerDelegate, LayoutFieldDelegate * delegate) { m_inputEventHandlerDelegate = inputEventHandlerDelegate; m_delegate = delegate; } bool isEditing() const override { return m_contentView.isEditing(); } - void setEditing(bool isEditing) override { m_contentView.setEditing(isEditing); } + void setEditing(bool isEditing) override; void clearLayout() { m_contentView.clearLayout(); } void scrollToCursor() { scrollToBaselinedRect(m_contentView.cursorRect(), m_contentView.cursor()->baseline()); @@ -59,7 +59,7 @@ private: public: ContentView(); bool isEditing() const { return m_isEditing; } - void setEditing(bool isEditing); + bool setEditing(bool isEditing); // returns True if LayoutField should reload void setBackgroundColor(KDColor c) { m_expressionView.setBackgroundColor(c); } void setCursor(Poincare::LayoutCursor cursor) { m_cursor = cursor; } void cursorPositionChanged() { layoutCursorSubview(); } diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index 740ea7bc6..705631002 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -19,10 +19,20 @@ LayoutField::ContentView::ContentView() : clearLayout(); } -void LayoutField::ContentView::setEditing(bool isEditing) { +bool LayoutField::ContentView::setEditing(bool isEditing) { m_isEditing = isEditing; markRectAsDirty(bounds()); + if (isEditing) { + /* showEmptyLayoutIfNeeded is done in LayoutField::handleEvent, so no need + * to do it here. */ + if (m_cursor.hideEmptyLayoutIfNeeded()) { + m_expressionView.layout().invalidAllSizesPositionsAndBaselines(); + return true; + } + } layoutSubviews(); + markRectAsDirty(bounds()); + return false; } void LayoutField::ContentView::clearLayout() { @@ -70,6 +80,13 @@ void LayoutField::ContentView::layoutCursorSubview() { m_cursorView.setFrame(KDRect(cursorTopLeftPosition, LayoutCursor::k_cursorWidth, m_cursor.cursorHeight())); } +void LayoutField::setEditing(bool isEditing) { + KDSize previousLayoutSize = m_contentView.minimalSizeForOptimalDisplay(); + if (m_contentView.setEditing(isEditing)) { + reload(previousLayoutSize); + } +} + CodePoint LayoutField::XNTCodePoint(CodePoint defaultXNTCodePoint) { CodePoint xnt = m_contentView.cursor()->layoutReference().XNTCodePoint(); if (xnt != UCodePointNull) { @@ -143,9 +160,9 @@ bool LayoutField::handleEventWithText(const char * text, bool indentation, bool bool LayoutField::handleEvent(Ion::Events::Event event) { bool didHandleEvent = false; + KDSize previousSize = minimalSizeForOptimalDisplay(); bool shouldRecomputeLayout = m_contentView.cursor()->showEmptyLayoutIfNeeded(); bool moveEventChangedLayout = false; - KDSize previousSize = minimalSizeForOptimalDisplay(); if (privateHandleMoveEvent(event, &moveEventChangedLayout)) { if (!isEditing()) { setEditing(true);