fix(api): nvim_set_current_win doesn't reset Visual mode (#37340)

Problem:
Using nvim_set_current_win() to switch windows while in Visual mode
causes E315 ml_get error when target buffer has fewer lines. This
doesn't happen with `:wincmd w` since it properly resets Visual mode
when switching buffers.

Solution:
Reset Visual mode when switching to another buffer, like `:wincmd w`.
This commit is contained in:
glepnir
2026-01-10 13:49:46 +08:00
committed by GitHub
parent cb77bd1b86
commit 63cbc95d45
2 changed files with 14 additions and 0 deletions

View File

@@ -65,6 +65,7 @@
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/msgpack_rpc/channel_defs.h"
#include "nvim/msgpack_rpc/unpacker.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/option_defs.h"
#include "nvim/option_vars.h"
@@ -975,6 +976,9 @@ void nvim_set_current_win(Window window, Error *err)
}
TRY_WRAP(err, {
if (win->w_buffer != curbuf) {
reset_VIsual_and_resel();
}
goto_tabpage_win(win_find_tabpage(win), win);
});
}