diff options
author | smolck <46855713+smolck@users.noreply.github.com> | 2021-08-14 12:19:05 -0500 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-09-27 14:47:53 +0200 |
commit | c7d30c152d1639523d05154e245ea60ed9a51a2b (patch) | |
tree | 9e329b4448ef83620d46160741791a6b3c4da86c /src/nvim/lua/stdlib.c | |
parent | 1d337d4e2f2265b13ecf19a3bc17ad302d3b0d96 (diff) | |
download | rneovim-c7d30c152d1639523d05154e245ea60ed9a51a2b.tar.gz rneovim-c7d30c152d1639523d05154e245ea60ed9a51a2b.tar.bz2 rneovim-c7d30c152d1639523d05154e245ea60ed9a51a2b.zip |
fix(api): notify dict watchers on nvim_set_var and vim.g setter
Co-authored-by: bfredl <bjorn.linse@gmail.com>
Co-authored-by: Christian Clason <c.clason@uni-graz.at>
Diffstat (limited to 'src/nvim/lua/stdlib.c')
-rw-r--r-- | src/nvim/lua/stdlib.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 9b1890403e..498f956ed9 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -369,12 +369,19 @@ int nlua_setvar(lua_State *lstate) return 0; } + bool watched = tv_dict_is_watched(dict); + if (del) { // Delete the key if (di == NULL) { // Doesn't exist, nothing to do return 0; } else { + // Notify watchers + if (watched) { + tv_dict_watcher_notify(dict, key.data, NULL, &di->di_tv); + } + // Delete the entry tv_dict_item_remove(dict, di); } @@ -388,17 +395,29 @@ int nlua_setvar(lua_State *lstate) return luaL_error(lstate, "Couldn't convert lua value"); } + typval_T oldtv = TV_INITIAL_VALUE; + if (di == NULL) { // Need to create an entry di = tv_dict_item_alloc_len(key.data, key.size); tv_dict_add(dict, di); } else { + if (watched) { + tv_copy(&di->di_tv, &oldtv); + } // Clear the old value tv_clear(&di->di_tv); } // Update the value tv_copy(&tv, &di->di_tv); + + // Notify watchers + if (watched) { + tv_dict_watcher_notify(dict, key.data, &tv, &oldtv); + tv_clear(&oldtv); + } + // Clear the temporary variable tv_clear(&tv); } |