diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-06-12 17:50:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-12 17:50:34 +0800 |
commit | b867f6c7c5cadd2bd09443a74a84aa55eb819e58 (patch) | |
tree | 39ba7df16823bb1ed8d2c5e32796928dc0051635 /src/nvim/eval/typval.c | |
parent | 551cc3a2a3e2ee180234910cbe2ef81bd37508de (diff) | |
parent | 4058f95d9dc9a58ab80f982c91b85ec1363c89c8 (diff) | |
download | rneovim-b867f6c7c5cadd2bd09443a74a84aa55eb819e58.tar.gz rneovim-b867f6c7c5cadd2bd09443a74a84aa55eb819e58.tar.bz2 rneovim-b867f6c7c5cadd2bd09443a74a84aa55eb819e58.zip |
Merge pull request #23996 from zeertzjq/vim-8.2.3191
vim-patch:8.2.{2533,3191,3202,partial:3335}
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r-- | src/nvim/eval/typval.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index a392d441cf..ec227a6b1a 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1507,6 +1507,21 @@ const char *tv_list_find_str(list_T *const l, const int n) return tv_get_string(TV_LIST_ITEM_TV(li)); } +/// Like tv_list_find() but when a negative index is used that is not found use +/// zero and set "idx" to zero. Used for first index of a range. +listitem_T *tv_list_find_index(list_T *const l, long *const idx) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + listitem_T *li = tv_list_find(l, (int)(*idx)); + if (li == NULL) { + if (*idx < 0) { + *idx = 0; + li = tv_list_find(l, (int)(*idx)); + } + } + return li; +} + /// Locate item in a list and return its index /// /// @param[in] l List to search. @@ -3004,12 +3019,13 @@ static void tv_dict_list(typval_T *const tv, typval_T *const rettv, const DictLi emsg(_(e_dictreq)); return; } + + tv_list_alloc_ret(rettv, tv_dict_len(tv->vval.v_dict)); if (tv->vval.v_dict == NULL) { + // NULL dict behaves like an empty dict return; } - tv_list_alloc_ret(rettv, tv_dict_len(tv->vval.v_dict)); - TV_DICT_ITER(tv->vval.v_dict, di, { typval_T tv_item = { .v_lock = VAR_UNLOCKED }; |