diff options
author | David McMackins II <contact@mcmackins.org> | 2016-09-05 08:03:18 -0500 |
---|---|---|
committer | David McMackins II <contact@mcmackins.org> | 2016-09-05 08:03:18 -0500 |
commit | 599557793eb7e55d45b4fcbe5e29c15e4af094d5 (patch) | |
tree | aaabe0bb7ef0cc5e7b4cbc51635a9cfd33c81205 | |
parent | 22ce8f012778ade86a56d4c38d7d5799be9b6822 (diff) |
Allow negative numbers in entry
-rw-r--r-- | doc/hotkeys.md | 1 | ||||
-rw-r--r-- | src/mode_default.c | 3 | ||||
-rw-r--r-- | src/tibeval.c | 11 |
3 files changed, 14 insertions, 1 deletions
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) |