Skip to content

Commit

Permalink
fix: correctly restore cursor position in original window (#2336)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3f1b579)
  • Loading branch information
cristiansofronie authored and Conni2461 committed May 24, 2023
1 parent f97f4a0 commit be8d87b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
9 changes: 0 additions & 9 deletions lua/telescope/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,8 @@ end
--- Close the Telescope window, usually used within an action
---@param prompt_bufnr number: The prompt bufnr
actions.close = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr)
local original_win_id = picker.original_win_id
local cursor_valid, original_cursor = pcall(a.nvim_win_get_cursor, original_win_id)

actions.close_pum(prompt_bufnr)

require("telescope.pickers").on_close_prompt(prompt_bufnr)
pcall(a.nvim_set_current_win, original_win_id)
if cursor_valid and a.nvim_get_mode().mode == "i" and picker._original_mode ~= "i" then
pcall(a.nvim_win_set_cursor, original_win_id, { original_cursor[1], original_cursor[2] + 1 })
end
end

--- Close the Telescope window, usually used within an action<br>
Expand Down
7 changes: 6 additions & 1 deletion lua/telescope/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,12 @@ function pickers.on_close_prompt(prompt_bufnr)
event = "BufLeave",
buffer = prompt_bufnr,
}
picker.close_windows(status)

vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<esc>", true, true, true), "n", true)
vim.defer_fn(function()
picker.close_windows(status)
end, 0)

mappings.clear(prompt_bufnr)
end

Expand Down

0 comments on commit be8d87b

Please sign in to comment.