diff --git a/apps/calculation/expression_field.cpp b/apps/calculation/expression_field.cpp index b96c4b1fe..587f4b1ed 100644 --- a/apps/calculation/expression_field.cpp +++ b/apps/calculation/expression_field.cpp @@ -1,6 +1,9 @@ #include "expression_field.h" #include +#include +#include +using namespace Poincare; namespace Calculation { bool ExpressionField::handleEvent(Ion::Events::Event event) { @@ -21,7 +24,31 @@ bool ExpressionField::handleEvent(Ion::Events::Event event) { event == Ion::Events::EE)) { handleEventWithText(Poincare::Symbol::k_ans); } - return(::ExpressionField::handleEvent(event)); + if (event == Ion::Events::Minus + && isEditing() + && fieldHasOnlyAMinus()) { + setText(Poincare::Symbol::k_ans); + } + return (::ExpressionField::handleEvent(event)); +} + +bool ExpressionField::fieldHasOnlyAMinus() const { + if (editionIsInTextField()) { + const char *inputBuffer = m_textField.draftTextBuffer(); + return (inputBuffer[0] == '-' && inputBuffer[1] == '\0'); + } + + Layout layout = m_layoutField.layout(); + if (layout.type() == LayoutNode::Type::HorizontalLayout && layout.numberOfChildren() == 1) { + Layout child = layout.childAtIndex(0); + if (child.type() == LayoutNode::Type::CodePointLayout) { + CodePointLayout &codePointLayout = static_cast(child); + if (codePointLayout.codePoint() == '-'){ + return true; + } + } + } + return false; } }