[escher/layout_field] Fix cursor position on Empty layout

Scenario: In the calculations app, write 1, Enter, write •|/2, go up,
then go down. There is a problem with the empty layout and the cursor.
This commit is contained in:
Léa Saviot
2019-07-31 10:52:52 +02:00
committed by Émilie Feral
parent ce15bc202d
commit c839fb52a3
2 changed files with 21 additions and 4 deletions

View File

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

View File

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