From dd8caaa82eff4b86f248ecf9ab268d561d71e315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 28 Aug 2017 10:25:18 +0200 Subject: [PATCH] [escher] In textfield: change the behaviour of clear event Change-Id: I6292faf383e40e7a9b00407bb5c052f92e49a1f6 --- escher/include/escher/text_field.h | 2 ++ escher/src/text_field.cpp | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/escher/include/escher/text_field.h b/escher/include/escher/text_field.h index 262e589dc..8fc19b78d 100644 --- a/escher/include/escher/text_field.h +++ b/escher/include/escher/text_field.h @@ -63,6 +63,7 @@ protected: KDCoordinate textHeight() const; KDCoordinate charWidth(); void deleteCharPrecedingCursor(); + bool deleteEndOfLine(); KDRect cursorRect(); View * subviewAtIndex(int index) override; /* In some app (ie Calculation), text fields record expression results whose @@ -90,6 +91,7 @@ protected: ContentView m_contentView; private: void deleteCharPrecedingCursor(); + bool deleteEndOfLine(); void scrollToCursor(); bool m_hasTwoBuffers; TextFieldDelegate * m_delegate; diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 40f169019..036f18590 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -184,6 +184,17 @@ void TextField::ContentView::deleteCharPrecedingCursor() { layoutSubviews(); } +bool TextField::ContentView::deleteEndOfLine() { + if (m_currentTextLength == m_currentCursorLocation) { + return false; + } + reload(); + m_currentTextLength = m_currentCursorLocation; + m_draftTextBuffer[m_currentCursorLocation] = 0; + layoutSubviews(); + return true; +} + KDRect TextField::ContentView::cursorRect() { return KDRect(m_currentCursorLocation * charWidth(), 0, m_cursorView.minimalSizeForOptimalDisplay()); } @@ -299,6 +310,15 @@ void TextField::deleteCharPrecedingCursor() { layoutSubviews(); } +bool TextField::deleteEndOfLine() { + if (m_contentView.deleteEndOfLine()) { + scrollToCursor(); + layoutSubviews(); + return true; + } + return false; +} + KDSize TextField::minimalSizeForOptimalDisplay() const { return KDSize(0, m_contentView.textHeight()); } @@ -384,7 +404,9 @@ bool TextField::handleEvent(Ion::Events::Event event) { return true; } if (event == Ion::Events::Clear && isEditing()) { - setEditing(true, true); + if (!deleteEndOfLine()) { + setEditing(true, true); + } return true; } if (event == Ion::Events::Copy && !isEditing()) {