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()) {