fix(lua): vim._with() doesn't save boolean options properly (#37354)

Problem:  vim._with() doesn't save boolean options with false values
          properly.
Solution: Use vim.F.if_nil().
This commit is contained in:
zeertzjq
2026-01-11 20:04:32 +08:00
committed by GitHub
parent cd0d26daf9
commit 94144d4678
4 changed files with 117 additions and 38 deletions

View File

@@ -1473,13 +1473,13 @@ local get_context_state = function(context)
-- Do not override already set state and fall back to `vim.NIL` for
-- state `nil` values (which still needs restoring later)
res[sc][name] = res[sc][name] or vim[sc][name] or vim.NIL
res[sc][name] = vim.F.if_nil(res[sc][name], vim[sc][name], vim.NIL)
-- Always track global option value to properly restore later.
-- This matters for at least `o` and `wo` (which might set either/both
-- local and global option values).
if sc ~= 'env' then
res.go[name] = res.go[name] or vim.go[name]
if sc ~= 'env' and res.go[name] == nil then
res.go[name] = vim.go[name]
end
end
end