[poincare] Dividing 3E-2 in Natural edition should give (3E-2)/|

This commit is contained in:
Léa Saviot
2018-11-13 14:32:38 +01:00
committed by EmilieNumworks
parent f052bd9088
commit 8d9ac798db
4 changed files with 30 additions and 6 deletions

View File

@@ -17,6 +17,7 @@ public:
// CharLayout
virtual void setChar(char c) { m_char = c; }
char character() const { return m_char; }
const KDFont * font() const { return m_font; }
void setFont(const KDFont * font) { m_font = font; }
@@ -24,6 +25,7 @@ public:
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override;
void moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) override;
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
bool isChar() const override { return true; }
bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const override;
// TreeNode
@@ -55,8 +57,10 @@ private:
class CharLayout final : public Layout {
public:
CharLayout(const CharLayoutNode * n) : Layout(n) {}
CharLayout(char c, const KDFont * font = KDFont::LargeFont);
const KDFont * font() const { return const_cast<CharLayout *>(this)->node()->font(); }
char character() const {return const_cast<CharLayout *>(this)->node()->character();}
private:
using Layout::node;
CharLayoutNode * node() { return static_cast<CharLayoutNode *>(Layout::node());}

View File

@@ -45,6 +45,7 @@ public:
bool isMatrix() const { return const_cast<Layout *>(this)->node()->isMatrix(); }
bool isVerticalOffset() const { return const_cast<Layout *>(this)->node()->isVerticalOffset(); }
bool isLeftParenthesis() const { return const_cast<Layout *>(this)->node()->isLeftParenthesis(); }
bool isChar() const { return const_cast<Layout *>(this)->node()->isChar(); }
bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const { return const_cast<Layout *>(this)->node()->isCollapsable(numberOfOpenParenthesis, goingLeft); }
int leftCollapsingAbsorbingChildIndex() const { return const_cast<Layout *>(this)->node()->leftCollapsingAbsorbingChildIndex(); }
int rightCollapsingAbsorbingChildIndex() const { return const_cast<Layout *>(this)->node()->rightCollapsingAbsorbingChildIndex(); }

View File

@@ -103,6 +103,7 @@ public:
virtual bool isRightBracket() const { return false; }
virtual bool isEmpty() const { return false; }
virtual bool isMatrix() const { return false; }
virtual bool isChar() const { return false; }
virtual bool hasUpperLeftIndex() const { return false; }
virtual char XNTChar() const {
LayoutNode * p = parent();

View File

@@ -32,17 +32,35 @@ int CharLayoutNode::serialize(char * buffer, int bufferSize, Preferences::PrintF
}
bool CharLayoutNode::isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const {
if (*numberOfOpenParenthesis <= 0
&& (m_char == '+'
|| m_char == '-'
if (*numberOfOpenParenthesis <= 0) {
if (m_char == '+'
|| m_char == '*'
|| m_char == Ion::Charset::MultiplicationSign
|| m_char == Ion::Charset::MiddleDot
|| m_char == Ion::Charset::Sto
|| m_char == '='
|| m_char == ','))
{
return false;
|| m_char == ',')
{
return false;
}
if (m_char == '-') {
/* If the expression is like 3E-200, we want '-' to be collapsable.
* Otherwise, '-' is not collapsable. */
Layout thisRef = CharLayout(this);
Layout parent = thisRef.parent();
if (!parent.isUninitialized()) {
int indexOfThis = parent.indexOfChild(thisRef);
if (indexOfThis > 0) {
Layout leftBrother = parent.childAtIndex(indexOfThis-1);
if (leftBrother.isChar()
&& static_cast<CharLayout&>(leftBrother).character() == Ion::Charset::Exponent)
{
return true;
}
}
}
return false;
}
}
return true;
}