mirror of
https://github.com/neovim/neovim
synced 2025-07-17 17:51:48 +00:00
fix(:let): fix error when applying operator to boolean option (#24030)
This commit is contained in:
@ -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;
|
new_n = num_modulus(cur_n, new_n); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clamp boolean values
|
if (curval.type == kOptValTypeNumber) {
|
||||||
if (newval.type == kOptValTypeBoolean && (new_n > 1 || new_n < -1)) {
|
newval = NUMBER_OPTVAL(new_n);
|
||||||
new_n = (new_n > 1) ? 1 : -1;
|
} 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
|
} else if (!hidden && is_string
|
||||||
&& curval.data.string.data != NULL && newval.data.string.data != NULL) { // string
|
&& curval.data.string.data != NULL && newval.data.string.data != NULL) { // string
|
||||||
OptVal newval_old = newval;
|
OptVal newval_old = newval;
|
||||||
|
@ -92,6 +92,20 @@ describe(':let', function()
|
|||||||
]])
|
]])
|
||||||
eq(1, eval('1'))
|
eq(1, eval('1'))
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
describe(':let and :const', function()
|
describe(':let and :const', function()
|
||||||
|
Reference in New Issue
Block a user