[escher] In textfield: change the behaviour of clear event

Change-Id: I6292faf383e40e7a9b00407bb5c052f92e49a1f6
This commit is contained in:
Émilie Feral
2017-08-28 10:25:18 +02:00
parent 54336b02b5
commit dd8caaa82e
2 changed files with 25 additions and 1 deletions

View File

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

View File

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