Merge pull request #19041 from lewis6991/globallocal

fix(api): nvim_set_option_value for global-local options
This commit is contained in:
bfredl
2022-06-25 11:09:55 +02:00
committed by GitHub
2 changed files with 25 additions and 4 deletions

View File

@@ -162,6 +162,19 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error
return;
}
// If:
// - window id is provided
// - scope is not provided
// - option is global or local to window (global-local)
//
// Then force scope to local since we don't want to change the global option
if (opt_type == SREQ_WIN && scope == 0) {
int flags = get_option_value_strict(name.data, NULL, NULL, opt_type, to);
if (flags & SOPT_GLOBAL) {
scope = OPT_LOCAL;
}
}
long numval = 0;
char *stringval = NULL;
@@ -460,11 +473,12 @@ void set_option_to(uint64_t channel_id, void *to, int type, String name, Object
stringval = value.data.string.data;
}
WITH_SCRIPT_CONTEXT(channel_id, {
const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL))
? 0 : (type == SREQ_GLOBAL)
? OPT_GLOBAL : OPT_LOCAL;
// For global-win-local options -> setlocal
// For win-local options -> setglobal and setlocal (opt_flags == 0)
const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL)) ? 0 :
(type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;
WITH_SCRIPT_CONTEXT(channel_id, {
access_option_value_for(name.data, &numval, &stringval, opt_flags, type, to, false, err);
});
}

View File

@@ -1428,6 +1428,13 @@ describe('lua stdlib', function()
vim.wo[1000].cole = 0
]]
eq(0, funcs.luaeval "vim.wo[1000].cole")
-- Can handle global-local values
exec_lua [[vim.o.scrolloff = 100]]
exec_lua [[vim.wo.scrolloff = 200]]
eq(200, funcs.luaeval "vim.wo.scrolloff")
exec_lua [[vim.wo.scrolloff = -1]]
eq(100, funcs.luaeval "vim.wo.scrolloff")
end)
describe('vim.opt', function()