diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-06-21 17:13:01 +0100 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2022-06-22 11:08:30 +0100 |
commit | d23465534a8ba5dac1758ffebdc7746138ee5210 (patch) | |
tree | de61e51307c2fa7ee25e84d2723fee7c6152415b /src/nvim/api/options.c | |
parent | dd591adf8a1d145b2fdf9115509bcc80c9ee7943 (diff) | |
download | rneovim-d23465534a8ba5dac1758ffebdc7746138ee5210.tar.gz rneovim-d23465534a8ba5dac1758ffebdc7746138ee5210.tar.bz2 rneovim-d23465534a8ba5dac1758ffebdc7746138ee5210.zip |
fix(api): nvim_set_option_value for global-local options
global-local window options need to be handled specially. When `win` is
given but `scope` is not, then we want to set the local version of the
option but not the global one, therefore we need to force
`scope='local'`.
Note this does not apply to window-local only options (e.g. 'number')
Example:
nvim_set_option_value('scrolloff', 10, {}) -- global-local window option; set global value
nvim_set_option_value('scrolloff', 20, {win=0}) -- global-local window option; set local value
nvim_set_option_value('number', true, {}) -- local window option
is now equivalent to:
nvim_set_option_value('scrolloff', 10, {})
nvim_set_option_value('scrolloff', 20, {win=0, scope='local'}) -- changed from before
nvim_set_option_value('number', true, {win=0}) -- unchanged from before
Only the global-local option with a `win` provided gets forced to local
scope.
Diffstat (limited to 'src/nvim/api/options.c')
-rw-r--r-- | src/nvim/api/options.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 3067a6e6b4..3766f47b20 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -156,6 +156,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; @@ -454,11 +467,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); }); } |