From 64b4012f9001bfe990e02f3372e9aa479d72c3f4 Mon Sep 17 00:00:00 2001 From: Ozero4 <114027116+Ozero4@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:11:43 +0100 Subject: [PATCH 1/4] Update expression_field.cpp --- apps/calculation/expression_field.cpp | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/calculation/expression_field.cpp b/apps/calculation/expression_field.cpp index b96c4b1fed6..587f4b1ede8 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; } } From 2671b6e0e18eb20259e4fc960064216134232070 Mon Sep 17 00:00:00 2001 From: Ozero4 <114027116+Ozero4@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:13:25 +0100 Subject: [PATCH 2/4] Update expression_field.cpp --- apps/calculation/expression_field.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/calculation/expression_field.cpp b/apps/calculation/expression_field.cpp index 587f4b1ede8..8096a6e1d4a 100644 --- a/apps/calculation/expression_field.cpp +++ b/apps/calculation/expression_field.cpp @@ -37,7 +37,6 @@ bool ExpressionField::fieldHasOnlyAMinus() const { 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); From 46f7eb5afede45e60996e270b8c41f9da88956d7 Mon Sep 17 00:00:00 2001 From: Ozero4 <114027116+Ozero4@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:14:01 +0100 Subject: [PATCH 3/4] Update expression_field.h --- apps/calculation/expression_field.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/calculation/expression_field.h b/apps/calculation/expression_field.h index 2844046286b..33477a87444 100644 --- a/apps/calculation/expression_field.h +++ b/apps/calculation/expression_field.h @@ -13,6 +13,8 @@ class ExpressionField : public ::ExpressionField { } protected: bool handleEvent(Ion::Events::Event event) override; +private: + bool fieldHasOnlyAMinus() const; }; } From 35799f9a0d6f35d6f954b40f74e6802e89ae5b76 Mon Sep 17 00:00:00 2001 From: Ozero4 <114027116+Ozero4@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:18:15 +0100 Subject: [PATCH 4/4] Update expression_field.h --- escher/include/escher/expression_field.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/escher/include/escher/expression_field.h b/escher/include/escher/expression_field.h index 7ecaf57d4dc..1619dfdd436 100644 --- a/escher/include/escher/expression_field.h +++ b/escher/include/escher/expression_field.h @@ -40,6 +40,10 @@ class ExpressionField : public Responder, public View { bool handleEvent(Ion::Events::Event event) override; void didBecomeFirstResponder() override; +protected: + TextField m_textField; + LayoutField m_layoutField; + private: static constexpr int k_textFieldBufferSize = TextField::maxBufferSize(); static constexpr KDCoordinate k_minimalHeight = 37; @@ -49,8 +53,6 @@ class ExpressionField : public Responder, public View { constexpr static KDCoordinate k_separatorThickness = Metric::CellSeparatorThickness; KDCoordinate inputViewHeight() const; KDCoordinate m_inputViewMemoizedHeight; - TextField m_textField; - LayoutField m_layoutField; }; #endif