From 576caa039fe6cbea630d5ab818a3f0dd0a06ce9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 19 Feb 2018 11:18:58 +0100 Subject: [PATCH] [apps][escher] Add methods 'handleEventWithText' in TextField and TextArea to fix bug in probability (adding a toolbox text from the calculations controller) --- .../edit_expression_controller.cpp | 3 +- apps/calculation/text_field.cpp | 7 +- apps/code/app.cpp | 24 ++----- apps/code/console_controller.cpp | 7 +- apps/code/console_edit_cell.cpp | 9 +-- apps/code/editor_controller.cpp | 21 +++--- apps/code/menu_controller.cpp | 2 +- apps/code/menu_controller.h | 2 +- apps/code/variable_box_controller.cpp | 12 +--- apps/math_toolbox.cpp | 7 +- apps/probability/calculation_controller.cpp | 2 +- apps/probability/calculation_controller.h | 2 +- apps/sequence/list/sequence_toolbox.cpp | 3 +- apps/shared/text_field_delegate_app.cpp | 4 +- apps/variable_box_controller.cpp | 6 +- escher/Makefile | 1 + escher/include/escher.h | 1 + escher/include/escher/text_area.h | 13 ++-- escher/include/escher/text_field.h | 1 + escher/include/escher/text_field_delegate.h | 2 +- escher/include/escher/text_input_helpers.h | 16 +++++ escher/src/text_area.cpp | 71 +++++++++++-------- escher/src/text_field.cpp | 58 +++++++-------- escher/src/text_input_helpers.cpp | 17 +++++ 24 files changed, 144 insertions(+), 147 deletions(-) create mode 100644 escher/include/escher/text_input_helpers.h create mode 100644 escher/src/text_input_helpers.cpp diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index c3476d3ca..43e37501d 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -61,8 +61,7 @@ const char * EditExpressionController::textBody() { void EditExpressionController::insertTextBody(const char * text) { TextField * tf = ((ContentView *)view())->textField(); tf->setEditing(true, false); - tf->insertTextAtLocation(text, tf->cursorLocation()); - tf->setCursorLocation(tf->cursorLocation() + strlen(text)); + tf->handleEventWithText(text); } bool EditExpressionController::handleEvent(Ion::Events::Event event) { diff --git a/apps/calculation/text_field.cpp b/apps/calculation/text_field.cpp index e9349c201..4e7d9c032 100644 --- a/apps/calculation/text_field.cpp +++ b/apps/calculation/text_field.cpp @@ -13,9 +13,7 @@ bool TextField::handleEvent(Ion::Events::Event event) { return false; } if (event == Ion::Events::Ans) { - insertTextAtLocation("ans", cursorLocation()); - setCursorLocation(cursorLocation() + strlen("ans")); - return true; + return handleEventWithText("ans"); } if (isEditing() && draftTextLength() == 0 && (event == Ion::Events::Multiplication || @@ -24,8 +22,7 @@ bool TextField::handleEvent(Ion::Events::Event event) { event == Ion::Events::Square || event == Ion::Events::Division || event == Ion::Events::Sto)) { - insertTextAtLocation("ans", cursorLocation()); - setCursorLocation(cursorLocation() + strlen("ans")); + handleEventWithText("ans"); } return(::TextField::handleEvent(event)); } diff --git a/apps/code/app.cpp b/apps/code/app.cpp index dcbd81afa..d7c99c0c1 100644 --- a/apps/code/app.cpp +++ b/apps/code/app.cpp @@ -1,7 +1,6 @@ #include "app.h" #include "../apps_container.h" #include "code_icon.h" -#include "../shared/toolbox_helpers.h" #include "../i18n.h" namespace Code { @@ -80,27 +79,12 @@ App::App(Container * container, Snapshot * snapshot) : m_codeStackViewController(&m_modalViewController, &m_listFooter), m_toolboxActionForTextArea([](void * sender, const char * text) { TextArea * textArea = static_cast