From 107e50b25e4b9098c0d1b4c34fec4bb17a9c7ad7 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 23 Aug 2020 18:03:41 -0400 Subject: vim-patch:8.2.1517: cannot easily get the character under the cursor Problem: Cannot easily get the character under the cursor. Solution: Add the {chars} argument to strpart(). https://github.com/vim/vim/commit/6c53fca02301ff871cddc1c74c388e23e53a424a --- src/nvim/eval/funcs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/eval/funcs.c') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 18e514b9a0..8e0e420eb0 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -9946,6 +9946,16 @@ static void f_strpart(typval_T *argvars, typval_T *rettv, FunPtr fptr) len = slen - n; } + if (argvars[2].v_type != VAR_UNKNOWN && argvars[3].v_type != VAR_UNKNOWN) { + int off; + + // length in characters + for (off = n; off < (int)slen && len > 0; len--) { + off += utfc_ptr2len((char_u *)p + off); + } + len = off - n; + } + rettv->v_type = VAR_STRING; rettv->vval.v_string = (char_u *)xmemdupz(p + n, (size_t)len); } -- cgit