Skip to content

Commit dbb073b

Browse files
committed
fix(pick): more carefully restore cursor when setting current window
Details: - Plain "cache cursor -> set current window -> restore cursor" can fail if setting current window leads to changing the buffer it displays (cached cursor becomes outdated as it is for the other buffer). One example is 'mini.files' default explorer: it automatically switches to the alternative buffer on (second) `BufEnter` in the buffer for directory path. - No additional test, since the code path is for Neovim<0.10 which is planned to be removed soon-ish. Resolve #2275
1 parent ca9adcf commit dbb073b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lua/mini/pick.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,9 +3623,9 @@ H.set_curwin = function(win_id)
36233623
if not H.is_valid_win(win_id) then return end
36243624
-- Explicitly preserve cursor to fix Neovim<0.10 after choosing position in
36253625
-- already shown buffer
3626-
local cursor = vim.api.nvim_win_get_cursor(win_id)
3626+
local buf_id, cursor = vim.api.nvim_win_get_buf(win_id), vim.api.nvim_win_get_cursor(win_id)
36273627
vim.api.nvim_set_current_win(win_id)
3628-
H.set_cursor(win_id, cursor[1], cursor[2] + 1)
3628+
if buf_id == vim.api.nvim_win_get_buf(win_id) then H.set_cursor(win_id, cursor[1], cursor[2] + 1) end
36293629
end
36303630

36313631
H.clear_namespace = function(buf_id, ns_id) pcall(vim.api.nvim_buf_clear_namespace, buf_id, ns_id, 0, -1) end

0 commit comments

Comments
 (0)