cleanup
This commit is contained in:
parent
8be2fbcfd8
commit
be762b036a
|
@ -31,7 +31,6 @@ function Lf:new(config)
|
||||||
self:__set_argv()
|
self:__set_argv()
|
||||||
self.bufnr = 0
|
self.bufnr = 0
|
||||||
self.view_idx = 1
|
self.view_idx = 1
|
||||||
self.action = "drop"
|
|
||||||
-- Needs to be grabbed here before the terminal buffer is created
|
-- Needs to be grabbed here before the terminal buffer is created
|
||||||
self.signcolumn = o.signcolumn
|
self.signcolumn = o.signcolumn
|
||||||
|
|
||||||
|
@ -57,10 +56,6 @@ function Lf:start(path)
|
||||||
self:__open_in(path)
|
self:__open_in(path)
|
||||||
self:__set_cmd_wrapper()
|
self:__set_cmd_wrapper()
|
||||||
|
|
||||||
self.term.on_open = function(term)
|
|
||||||
self:__on_open(term)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.term.on_exit = function(term, _, _, _)
|
self.term.on_exit = function(term, _, _, _)
|
||||||
self:__callback(term)
|
self:__callback(term)
|
||||||
uv.fs_unlink(self.tmp_id)
|
uv.fs_unlink(self.tmp_id)
|
||||||
|
@ -109,7 +104,6 @@ function Lf:__set_cmd_wrapper()
|
||||||
self.tmp_lastdir = os.tmpname()
|
self.tmp_lastdir = os.tmpname()
|
||||||
self.tmp_id = os.tmpname()
|
self.tmp_id = os.tmpname()
|
||||||
|
|
||||||
-- FIX: non existing file in buffer causes an error message
|
|
||||||
local selection = self.term.dir
|
local selection = self.term.dir
|
||||||
if fn.fnamemodify(self.curfile, ":h") == self.term.dir then
|
if fn.fnamemodify(self.curfile, ":h") == self.term.dir then
|
||||||
selection = self.curfile
|
selection = self.curfile
|
||||||
|
@ -127,35 +121,6 @@ function Lf:__set_cmd_wrapper()
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
|
||||||
---On open closure to run in the `Terminal`
|
|
||||||
---@param term Terminal
|
|
||||||
function Lf:__on_open(term)
|
|
||||||
self.bufnr = term.bufnr
|
|
||||||
self.winid = term.window
|
|
||||||
|
|
||||||
-- cmd("silent! doautocmd User LfTermEnter")
|
|
||||||
|
|
||||||
-- -- Wrap needs to be set, otherwise the window isn't aligned on resize
|
|
||||||
-- api.nvim_win_call(self.winid, function()
|
|
||||||
-- vim.wo.showbreak = "NONE"
|
|
||||||
-- vim.wo.wrap = true
|
|
||||||
-- vim.wo.sidescrolloff = 0
|
|
||||||
-- vim.wo.scrolloff = 0
|
|
||||||
-- vim.wo.scrollbind = false
|
|
||||||
-- end)
|
|
||||||
--
|
|
||||||
-- if self.cfg.tmux then
|
|
||||||
-- utils.tmux(true)
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- -- Don't know why whenever wrap is set in the terminal, a weird resize happens.
|
|
||||||
-- -- Because of that, this is needed here.
|
|
||||||
-- vim.defer_fn(function()
|
|
||||||
-- cmd("silent! doautoall VimResized")
|
|
||||||
-- end, 800)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function read_file(path)
|
local function read_file(path)
|
||||||
-- tonumber(444, 8) == 292
|
-- tonumber(444, 8) == 292
|
||||||
local fd = assert(uv.fs_open(fn.expand(path), "r", 292))
|
local fd = assert(uv.fs_open(fn.expand(path), "r", 292))
|
||||||
|
@ -171,21 +136,13 @@ end
|
||||||
---
|
---
|
||||||
---@param term Terminal
|
---@param term Terminal
|
||||||
function Lf:__callback(term)
|
function Lf:__callback(term)
|
||||||
if (self.action == "cd" or self.action == "lcd")
|
if uv.fs_stat(self.tmp_sel) then
|
||||||
and uv.fs_stat(self.tmp_lastdir)
|
|
||||||
then
|
|
||||||
local last_dir = read_file(self.tmp_lastdir)
|
|
||||||
if type(last_dir) == "string" then
|
|
||||||
cmd(("%s %s"):format(self.action, fn.fnameescape(last_dir)))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
elseif uv.fs_stat(self.tmp_sel) then
|
|
||||||
term:close()
|
term:close()
|
||||||
for fname in io.lines(self.tmp_sel) do
|
for fname in io.lines(self.tmp_sel) do
|
||||||
local stat = uv.fs_stat(fname)
|
local stat = uv.fs_stat(fname)
|
||||||
if type(stat) == "table" then
|
if type(stat) == "table" then
|
||||||
local fesc = fn.fnameescape(fname)
|
local fesc = fn.fnameescape(fname)
|
||||||
cmd(("%s %s"):format(self.action, fesc))
|
cmd(("drop %s"):format(fesc))
|
||||||
local args = table.concat(self.arglist, " ")
|
local args = table.concat(self.arglist, " ")
|
||||||
if string.len(args) > 0 then
|
if string.len(args) > 0 then
|
||||||
cmd.argadd(args)
|
cmd.argadd(args)
|
||||||
|
@ -195,11 +152,6 @@ function Lf:__callback(term)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Reset the action
|
|
||||||
vim.defer_fn(function()
|
|
||||||
self.action = "drop"
|
|
||||||
end, 1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
|
|
|
@ -82,6 +82,5 @@ return M
|
||||||
---@field id number? Current `lf` session id
|
---@field id number? Current `lf` session id
|
||||||
---@field bufnr number The open file's buffer number
|
---@field bufnr number The open file's buffer number
|
||||||
---@field arglist string[] The argument list to neovim
|
---@field arglist string[] The argument list to neovim
|
||||||
---@field action string The current action to open the file
|
|
||||||
---@field signcolumn string The signcolumn set by the user before the terminal buffer overrides it
|
---@field signcolumn string The signcolumn set by the user before the terminal buffer overrides it
|
||||||
---@field start fun(self, path: string?)
|
---@field start fun(self, path: string?)
|
||||||
|
|
Reference in New Issue