From 599557793eb7e55d45b4fcbe5e29c15e4af094d5 Mon Sep 17 00:00:00 2001 From: David McMackins II Date: Mon, 5 Sep 2016 08:03:18 -0500 Subject: Allow negative numbers in entry --- doc/hotkeys.md | 1 + src/mode_default.c | 3 ++- src/tibeval.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/hotkeys.md b/doc/hotkeys.md index 4fe82bf..1f33ed3 100644 --- a/doc/hotkeys.md +++ b/doc/hotkeys.md @@ -34,3 +34,4 @@ Hotkey List - `s`: `sin(` - `t`: `tan(` - `$`: `→` (stores value to left into variable to right) +- `C--`: `-` (inserts minus at the beginning without inserting `Ans`) diff --git a/src/mode_default.c b/src/mode_default.c index 8324c95..fe47654 100644 --- a/src/mode_default.c +++ b/src/mode_default.c @@ -278,7 +278,8 @@ default_input (struct screen *screen, SDL_KeyboardEvent *key) int normal = normalize_keycode (code, mod); if (normal) { - if (is_math_operator (normal) && 0 == state->entry.len) + if (is_math_operator (normal) && 0 == state->entry.len + && !(mod & KMOD_CTRL)) { int rc = entry_write (state, TIB_CHAR_ANS); if (rc) diff --git a/src/tibeval.c b/src/tibeval.c index 43c93f0..3f1f182 100644 --- a/src/tibeval.c +++ b/src/tibeval.c @@ -243,6 +243,17 @@ tib_eval (const struct tib_expr *in) if (tib_errno) return NULL; + /* check for sign operator at the beginning of number */ + if (expr.len > 0 && ('-' == expr.data[0] || '+' == expr.data[0])) + { + tib_errno = tib_expr_insert (&expr, 0, '0'); + if (tib_errno) + { + tib_expr_destroy (&expr); + return NULL; + } + } + /* check for implicit closing parentheses and close them */ tib_errno = tib_eval_close_parens (&expr); if (tib_errno) -- cgit v1.2.3