diff options
author | jyn <github@jyn.dev> | 2025-04-08 08:54:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-08 05:54:32 -0700 |
commit | 3647b821ea69ea095ccc4bf8c265df474333a5d5 (patch) | |
tree | 626ae9dfd2fda5fb8fb150a1ea2f72926240c002 /src/nvim/ex_cmds.c | |
parent | 5b1561bb717eae8781ff62646c675c7e842e4444 (diff) | |
download | rneovim-3647b821ea69ea095ccc4bf8c265df474333a5d5.tar.gz rneovim-3647b821ea69ea095ccc4bf8c265df474333a5d5.tar.bz2 rneovim-3647b821ea69ea095ccc4bf8c265df474333a5d5.zip |
fix(editor): respect [+cmd] when executing :drop #33339
Problem:
Normally, `:drop +41 foo.txt` will open foo.txt with the cursor on line
41. But if foo.txt is already open, it instead is a no-op, even if the
cursor is on a different line.
Steps to reproduce:
nvim --clean foo.txt
:drop +30 foo.txt
Solution:
Handle +cmd in ex_drop().
Diffstat (limited to 'src/nvim/ex_cmds.c')
-rw-r--r-- | src/nvim/ex_cmds.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 275feb7589..72fd009c32 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2064,6 +2064,29 @@ theend: return retval; } +/// set v:swapcommand for the SwapExists autocommands. +/// +/// @param command [+cmd] to be executed (e.g. +10). +/// @param newlnum if > 0: put cursor on this line number (if possible) +// +/// @return 1 if swapcommand was actually set, 0 otherwise +bool set_swapcommand(char *command, linenr_T newlnum) +{ + if ((command == NULL && newlnum <= 0) || *get_vim_var_str(VV_SWAPCOMMAND) != NUL) { + return false; + } + const size_t len = (command != NULL) ? strlen(command) + 3 : 30; + char *const p = xmalloc(len); + if (command != NULL) { + vim_snprintf(p, len, ":%s\r", command); + } else { + vim_snprintf(p, len, "%" PRId64 "G", (int64_t)newlnum); + } + set_vim_var_string(VV_SWAPCOMMAND, p, -1); + xfree(p); + return true; +} + /// start editing a new file /// /// @param fnum file number; if zero use ffname/sfname @@ -2197,20 +2220,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum oldwin = NULL; } - if ((command != NULL || newlnum > 0) - && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) { - // Set v:swapcommand for the SwapExists autocommands. - const size_t len = (command != NULL) ? strlen(command) + 3 : 30; - char *const p = xmalloc(len); - if (command != NULL) { - vim_snprintf(p, len, ":%s\r", command); - } else { - vim_snprintf(p, len, "%" PRId64 "G", (int64_t)newlnum); - } - set_vim_var_string(VV_SWAPCOMMAND, p, -1); - did_set_swapcommand = true; - xfree(p); - } + did_set_swapcommand = set_swapcommand(command, newlnum); // If we are starting to edit another file, open a (new) buffer. // Otherwise we re-use the current buffer. |