diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-12 06:08:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-12 06:08:07 +0800 |
commit | 713311be62db5c5453bcd0a7f1dbed8d1d1add15 (patch) | |
tree | ad7e949fcda8d40a01872c398d21f27e15600fe1 /src/nvim/keycodes.c | |
parent | 6e0c36ba0e6691401726fd4215f89729138ba82f (diff) | |
download | rneovim-713311be62db5c5453bcd0a7f1dbed8d1d1add15.tar.gz rneovim-713311be62db5c5453bcd0a7f1dbed8d1d1add15.tar.bz2 rneovim-713311be62db5c5453bcd0a7f1dbed8d1d1add15.zip |
vim-patch:9.0.1687: mapset() not properly handling script ID (#24666)
Problem: mapset() not properly handling script ID
Solution: replace_termcodes() may accept a script ID
closes: vim/vim#12699
closes: vim/vim#12697
https://github.com/vim/vim/commit/7e0bae024d4c1673cff31763227ad52b936fa56f
Diffstat (limited to 'src/nvim/keycodes.c')
-rw-r--r-- | src/nvim/keycodes.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/nvim/keycodes.c b/src/nvim/keycodes.c index 34442ae5c4..6c64a2ca4a 100644 --- a/src/nvim/keycodes.c +++ b/src/nvim/keycodes.c @@ -873,6 +873,7 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// If `*bufp` is non-NULL, it will be used directly, /// and is assumed to be 128 bytes long (enough for transcoding LHS of mapping), /// and will be set to NULL in case of failure. +/// @param[in] sid_arg Script ID to use for <SID>, or 0 to use current_sctx /// @param[in] flags REPTERM_FROM_PART see above /// REPTERM_DO_LT also translate <lt> /// REPTERM_NO_SPECIAL do not accept <key> notation @@ -882,7 +883,8 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag) /// /// @return The same as what `*bufp` is set to. char *replace_termcodes(const char *const from, const size_t from_len, char **const bufp, - const int flags, bool *const did_simplify, const int cpo_flags) + const scid_T sid_arg, const int flags, bool *const did_simplify, + const int cpo_flags) FUNC_ATTR_NONNULL_ARG(1, 3) { ssize_t i; @@ -916,15 +918,15 @@ char *replace_termcodes(const char *const from, const size_t from_len, char **co // Replace <SID> by K_SNR <script-nr> _. // (room: 5 * 6 = 30 bytes; needed: 3 + <nr> + 1 <= 14) if (end - src >= 4 && STRNICMP(src, "<SID>", 5) == 0) { - if (current_sctx.sc_sid <= 0) { + if (sid_arg < 0 || (sid_arg == 0 && current_sctx.sc_sid <= 0)) { emsg(_(e_usingsid)); } else { + const scid_T sid = sid_arg != 0 ? sid_arg : current_sctx.sc_sid; src += 5; result[dlen++] = (char)K_SPECIAL; result[dlen++] = (char)KS_EXTRA; result[dlen++] = KE_SNR; - snprintf(result + dlen, buf_len - dlen, "%" PRId64, - (int64_t)current_sctx.sc_sid); + snprintf(result + dlen, buf_len - dlen, "%" PRId64, (int64_t)sid); dlen += strlen(result + dlen); result[dlen++] = '_'; continue; |