Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-- devient ans- #361

Open
wants to merge 4 commits into
base: upsilon-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion apps/calculation/expression_field.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "expression_field.h"
#include <poincare/symbol.h>
#include <poincare/horizontal_layout.h>
#include <poincare/code_point_layout.h>

using namespace Poincare;
namespace Calculation {

bool ExpressionField::handleEvent(Ion::Events::Event event) {
Expand All @@ -21,7 +24,30 @@ 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<CodePointLayout &>(child);
if (codePointLayout.codePoint() == '-'){
return true;
}
}
}
return false;
}

}
2 changes: 2 additions & 0 deletions apps/calculation/expression_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ExpressionField : public ::ExpressionField {
}
protected:
bool handleEvent(Ion::Events::Event event) override;
private:
bool fieldHasOnlyAMinus() const;
};

}
Expand Down
6 changes: 4 additions & 2 deletions escher/include/escher/expression_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Loading