[escher/text_field] Fix privateHandleEvent text reset

This commit is contained in:
Léa Saviot
2018-11-21 11:58:00 +01:00
committed by Émilie Feral
parent 9c788d31d4
commit bf6da61ca2
2 changed files with 7 additions and 9 deletions

View File

@@ -7,9 +7,9 @@ class TextFieldDelegate {
public:
virtual bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) = 0;
virtual bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) = 0;
virtual bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { return false; };
virtual bool textFieldDidAbortEditing(TextField * textField) {return false;};
virtual bool textFieldDidHandleEvent(TextField * textField, bool returnValue, bool textSizeDidChange) { return returnValue; };
virtual bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { return false; }
virtual bool textFieldDidAbortEditing(TextField * textField) { return false; }
virtual bool textFieldDidHandleEvent(TextField * textField, bool returnValue, bool textSizeDidChange) { return returnValue; }
};
#endif

View File

@@ -262,7 +262,7 @@ bool TextField::privateHandleEvent(Ion::Events::Event event) {
* This will call textFieldDidAbortEditing if the textfield is still editing,
* which we do not want, as we are not really aborting edition, just
* displaying a pop-up before returning to edition.
* We thus set editiong to false. */
* We thus set editing to false. */
setEditing(false, m_hasTwoBuffers);
if (m_delegate->textFieldDidFinishEditing(this, text(), event)) {
/* We allow overscroll to avoid calling layoutSubviews twice because the
@@ -270,14 +270,12 @@ bool TextField::privateHandleEvent(Ion::Events::Event event) {
reloadScroll(true);
return true;
}
setEditing(true, m_hasTwoBuffers);
setEditing(true, false);
if (m_hasTwoBuffers) {
/* if the text was refused (textInputDidFinishEditing returned false, we
* reset the textfield in the same state as before */
char bufferDraft[ContentView::k_maxBufferSize];
strlcpy(bufferDraft, m_contentView.textBuffer(), ContentView::k_maxBufferSize);
setText(bufferText);
setText(bufferDraft);
setText(m_contentView.textBuffer());
strlcpy(m_contentView.textBuffer(), bufferText, ContentView::k_maxBufferSize);
setCursorLocation(cursorLoc);
}
return true;