[apps] Calculation: OK on an empty textfield re-do the last user input

kept in cache
This commit is contained in:
Émilie Feral
2018-01-31 14:53:53 +01:00
committed by EmilieNumworks
parent f9241bd7e6
commit 470767340a
2 changed files with 6 additions and 3 deletions

View File

@@ -51,6 +51,7 @@ EditExpressionController::EditExpressionController(Responder * parentResponder,
m_historyController(historyController),
m_calculationStore(calculationStore)
{
m_cacheBuffer[0] = 0;
}
const char * EditExpressionController::textBody() {
@@ -67,6 +68,7 @@ void EditExpressionController::insertTextBody(const char * text) {
bool EditExpressionController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Up) {
if (m_calculationStore->numberOfCalculations() > 0) {
m_cacheBuffer[0] = 0;
((ContentView *)view())->textField()->setEditing(false, false);
app()->setFirstResponder(m_historyController);
}
@@ -83,10 +85,9 @@ void EditExpressionController::didBecomeFirstResponder() {
}
bool EditExpressionController::textFieldDidReceiveEvent(::TextField * textField, Ion::Events::Event event) {
if (textField->isEditing() && textField->textFieldShouldFinishEditing(event) && textField->draftTextLength() == 0 && m_calculationStore->numberOfCalculations() > 0) {
if (textField->isEditing() && textField->textFieldShouldFinishEditing(event) && textField->draftTextLength() == 0 && m_cacheBuffer[0] != 0) {
App * calculationApp = (App *)app();
const char * lastTextBody = m_calculationStore->calculationAtIndex(m_calculationStore->numberOfCalculations()-1)->inputText();
m_calculationStore->push(lastTextBody, calculationApp->localContext());
m_calculationStore->push(m_cacheBuffer, calculationApp->localContext());
m_historyController->reload();
((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);
return true;
@@ -96,6 +97,7 @@ bool EditExpressionController::textFieldDidReceiveEvent(::TextField * textField,
bool EditExpressionController::textFieldDidFinishEditing(::TextField * textField, const char * text, Ion::Events::Event event) {
App * calculationApp = (App *)app();
strlcpy(m_cacheBuffer, textBody(), TextField::maxBufferSize());
m_calculationStore->push(textBody(), calculationApp->localContext());
m_historyController->reload();
((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1);