From 479213668f0fba7d76b2f3f07d6e6cc2101b6177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 13 Jan 2017 15:18:37 +0100 Subject: [PATCH] [apps] Fix bug: display 'n' when clicking on XNT in sum and product function Change-Id: Ic3151274a6ee8d0229ec8fda29f911923d6c026c --- apps/expression_text_field_delegate.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/expression_text_field_delegate.cpp b/apps/expression_text_field_delegate.cpp index b6c8aa125..ad0bf4e8a 100644 --- a/apps/expression_text_field_delegate.cpp +++ b/apps/expression_text_field_delegate.cpp @@ -9,13 +9,16 @@ const char * ExpressionTextFieldDelegate::XNT() { bool ExpressionTextFieldDelegate::cursorInToken(TextField * textField, const char * token) { const char * text = textField->text(); - int cursorLocation = textField->cursorLocation(); + int location = textField->cursorLocation(); int tokenLength = strlen(token); - if (cursorLocation - tokenLength < 0) { + while (text[location] != '(') { + location --; + } + if (location - tokenLength < 0) { return false; } char previousToken[10]; - strlcpy(previousToken, text+cursorLocation-tokenLength, tokenLength+1); + strlcpy(previousToken, text+location-tokenLength, tokenLength+1); if (strcmp(previousToken, token) == 0) { return true; } @@ -61,7 +64,7 @@ bool ExpressionTextFieldDelegate::textFieldDidReceiveEvent(TextField * textField textField->setEditing(true); textField->setText(""); } - if (cursorInToken(textField, "sum(") || cursorInToken(textField, "product(")) { + if (cursorInToken(textField, "sum") || cursorInToken(textField, "product")) { textField->insertTextAtLocation("n", textField->cursorLocation()); textField->setCursorLocation(textField->cursorLocation()+strlen("n")); return true;