neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 1f8fb7c00048bc217bb9a2bf29c58630d1810d6e
parent d81f78713b76e667491dba27ef6841f05d561d68
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Thu, 15 Jun 2023 12:36:21 +0800

fix(:let): fix error when applying operator to boolean option (#24030)


Diffstat:
Msrc/nvim/eval/vars.c | 9++++-----
Mtest/functional/vimscript/let_spec.lua | 14++++++++++++++
2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c @@ -817,12 +817,11 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const, new_n = num_modulus(cur_n, new_n); break; } - // clamp boolean values - if (newval.type == kOptValTypeBoolean && (new_n > 1 || new_n < -1)) { - new_n = (new_n > 1) ? 1 : -1; + if (curval.type == kOptValTypeNumber) { + newval = NUMBER_OPTVAL(new_n); + } else { + newval = BOOLEAN_OPTVAL(new_n == 0 ? kFalse : (new_n >= 1 ? kTrue : kNone)); } - - newval = kOptValTypeNumber ? NUMBER_OPTVAL(new_n) : BOOLEAN_OPTVAL((TriState)new_n); } else if (!hidden && is_string && curval.data.string.data != NULL && newval.data.string.data != NULL) { // string OptVal newval_old = newval; diff --git a/test/functional/vimscript/let_spec.lua b/test/functional/vimscript/let_spec.lua @@ -92,6 +92,20 @@ describe(':let', function() ]]) eq(1, eval('1')) end) + + it('can apply operator to boolean option', function() + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways -= 1') + eq(false, meths.get_option_value('equalalways', {})) + command('let &equalalways += 1') + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways *= 1') + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways /= 1') + eq(true, meths.get_option_value('equalalways', {})) + command('let &equalalways %= 1') + eq(false, meths.get_option_value('equalalways', {})) + end) end) describe(':let and :const', function()