Skip to content

Commit 5921997

Browse files
phanenibhagwan
authored andcommitted
fix(preview): set cursor pos (entry.lnum/col) on vterm cmd exit
sometime it don't seem correct, but should better than none
1 parent 42c7024 commit 5921997

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

lua/fzf-lua/previewer/builtin.lua

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -947,13 +947,16 @@ local start_cmd = function(buf, entry, opts)
947947
if err then close(err) end
948948
if data then try_send(data) end
949949
end)
950-
else
951-
on_exit = vim.schedule_wrap(function(obj0)
952-
if not api.nvim_buf_is_valid(buf) then return end
950+
end
951+
on_exit = vim.schedule_wrap(function(obj0)
952+
if not api.nvim_buf_is_valid(buf) then return end
953+
if entry.cmd_stream ~= false then
954+
opts.on_exit()
955+
else
953956
chan = api.nvim_open_term(buf, {})
954957
try_send(vim.trim(obj0.stderr or "") ~= "" and obj0.stderr or obj0.stdout or "")
955-
end)
956-
end
958+
end
959+
end)
957960
local sopts = entry.cmd_opts or {}
958961
sopts = vim.tbl_deep_extend("force", sopts, { stdout = stdout, stderr = stdout })
959962
obj = vim.system(entry.cmd, sopts, on_exit)
@@ -1068,6 +1071,8 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
10681071
if opened then return end
10691072
opened = true
10701073
self:set_preview_buf(tmpbuf, true)
1074+
end,
1075+
on_exit = function()
10711076
self:preview_buf_post(entry)
10721077
end,
10731078
})
@@ -1504,10 +1509,11 @@ end
15041509
---@param min_winopts boolean?
15051510
function Previewer.buffer_or_file:preview_buf_post(entry, min_winopts)
15061511
if not self.win or not self.win:validate_preview() then return end
1507-
if not utils.is_term_buffer(self.preview_bufnr) then
1508-
-- set cursor highlights for line|col or tag
1509-
self:set_cursor_hl(entry)
15101512

1513+
-- set cursor highlights for line|col or tag
1514+
self:set_cursor_hl(entry)
1515+
1516+
if not utils.is_term_buffer(self.preview_bufnr) then
15111517
local syntax = function()
15121518
if self.syntax then
15131519
self:do_syntax(entry)
@@ -1945,6 +1951,7 @@ function Previewer.vterm:new(o, opts, previewer)
19451951
end
19461952

19471953
function Previewer.vterm:parse_entry(entry_str)
1954+
local entry = Previewer.vterm.super.parse_entry(self, entry_str)
19481955
local spec = self.previewer:cmdline() ---@type fzf-lua.preview.spec
19491956
assert(type(spec) == "table" and spec.fn, "invalid vterm previewer spec")
19501957
local preview = assert(self.win.layout.preview)
@@ -1953,10 +1960,10 @@ function Previewer.vterm:parse_entry(entry_str)
19531960
if spec.type == "cmd" then
19541961
local cmdspec = type(res) == "table" and res or { cmd = { "sh", "-c", res }, env = nil }
19551962
local cmd = type(cmdspec.cmd) == "table" and cmdspec.cmd or { "sh", "-c", cmdspec.cmd }
1956-
return { cmd = cmd, cmd_opts = { env = cmdspec.env } }
1963+
return { cmd = cmd, cmd_opts = { env = cmdspec.env }, line = entry.line, col = entry.col }
19571964
else
19581965
assert(type(res) == "table", res)
1959-
return { content = res, open_term = true }
1966+
return { content = res, open_term = true, line = entry.line, col = entry.col }
19601967
end
19611968
end
19621969

0 commit comments

Comments
 (0)