fix: restore cursor to correct position on picker close

This commit is contained in:
James Trew
2024-01-10 23:11:20 +01:00
committed by Simon Hauser
parent 4367e05c06
commit 6a7dd9b399
4 changed files with 40 additions and 27 deletions
+2 -19
View File
@@ -13,7 +13,6 @@
local a = vim.api
local log = require "telescope.log"
local Path = require "plenary.path"
local state = require "telescope.state"
local utils = require "telescope.utils"
@@ -197,7 +196,7 @@ action_set.edit = function(prompt_bufnr, command)
-- prevents restarting lsp server
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
filename = Path:new(filename):normalize(vim.loop.cwd())
pcall(vim.cmd, string.format("%s %s", command, vim.fn.fnameescape(filename)))
pcall(vim.cmd[command], vim.fn.fnameescape(filename))
end
end
@@ -208,23 +207,7 @@ action_set.edit = function(prompt_bufnr, command)
end)
end
local pos = vim.api.nvim_win_get_cursor(0)
if col == nil then
if row == pos[1] then
col = pos[2] + 1
elseif row == nil then
row, col = pos[1], pos[2] + 1
else
col = 1
end
end
if row and col then
local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, { row, col })
if not ok then
log.debug("Failed to move to cursor:", err_msg, row, col)
end
end
utils.set_window_cursor(a.nvim_get_current_win(), row, col)
end
--- Scrolls the previewer up or down.