Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 187d3e93 authored by Hans Boehm's avatar Hans Boehm
Browse files

Improve logic for when to display instant result

Bug: 21497671

Fix mChangedValue handling, so that it is only reset after an actual
evaluation, and is set when an expression is "collapsed".

Consistently produce instant results for solitary pre-evaluated
expressions if and only if they involve an abbreviation.

Change-Id: I4e1f824e2353cbe78b1827f3930c72666832cff4
parent 7c07c19e
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -305,7 +305,12 @@ class CalculatorExpr {
            return KeyMaps.translateResult(mShortRep);
        }
        @Override
        TokenKind kind() { return TokenKind.PRE_EVAL; }
        TokenKind kind() {
            return TokenKind.PRE_EVAL;
        }
        boolean hasEllipsis() {
            return mShortRep.lastIndexOf(KeyMaps.ELLIPSIS) != -1;
        }
    }

    static Token newToken(DataInput in) throws IOException {
@@ -916,10 +921,10 @@ class CalculatorExpr {
        }
        for (int i = first; i < last; ++i) {
            Token t1 = mExpr.get(i);
            if (!(t1 instanceof Constant)) return true;
            // We consider preevaluated expressions "interesting",
            // since the evaluation will usually result in more precision
            // than the "short representation".
            if (t1 instanceof Operator
                    || t1 instanceof PreEval && ((PreEval)t1).hasEllipsis()) {
                return true;
            }
        }
        return false;
    }
+7 −6
Original line number Diff line number Diff line
@@ -188,9 +188,8 @@ class Evaluator {
        // Currently running expression evaluator, if any.

    private boolean mChangedValue;
        // Last insertion or deletion may have changed the display value
        // of the expression.
        // We handle deletions very conservatively.
        // The expression may have changed since the last evaluation in ways that would
        // affect its value.

    Evaluator(Calculator calculator,
              CalculatorResult resultDisplay) {
@@ -791,6 +790,7 @@ class Evaluator {
        clearCache();
        mEvaluator = new AsyncDisplayResult(mDegreeMode, false);
        mEvaluator.execute();
        mChangedValue = false;
    }

    // Ensure that we either display a result or complain.
@@ -835,6 +835,7 @@ class Evaluator {
            // Approximation of constructive reals should be thread-safe,
            // so we can let that continue until it notices the cancellation.
            mEvaluator = null;
            mChangedValue = true;    // Didn't do the expected evaluation.
            return true;
        }
        return false;
@@ -874,9 +875,8 @@ class Evaluator {
            add10pow();  // Handled as macro expansion.
            return true;
        } else {
            mChangedValue = (KeyMaps.digVal(id) != KeyMaps.NOT_DIGIT
                    || KeyMaps.isSuffix(id)
                    || id == R.id.const_pi || id == R.id.const_e);
            mChangedValue = mChangedValue || (KeyMaps.digVal(id) != KeyMaps.NOT_DIGIT
                    || KeyMaps.isSuffix(id) || id == R.id.const_pi || id == R.id.const_e);
            return mExpr.add(id);
        }
    }
@@ -918,6 +918,7 @@ class Evaluator {
        final CalculatorExpr abbrvExpr = getResultExpr();
        clear();
        mExpr.append(abbrvExpr);
        mChangedValue = true;
    }

    // Same as above, but put result in mSaved, leaving mExpr alone.