Merge pull request #61 from kyazdani42/fix/window-handling
Fix/window handling
This commit is contained in:
@@ -129,7 +129,7 @@ local function do_copy(source, destination)
|
|||||||
luv.fs_mkdir(destination, source_stats.mode)
|
luv.fs_mkdir(destination, source_stats.mode)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local name, t = luv.fs_scandir_next(handle)
|
local name, _ = luv.fs_scandir_next(handle)
|
||||||
if not name then break end
|
if not name then break end
|
||||||
|
|
||||||
local new_name = source..'/'..name
|
local new_name = source..'/'..name
|
||||||
@@ -173,15 +173,15 @@ local function do_paste(node, action_type, action_fn)
|
|||||||
local dest_stats = luv.fs_stat(dest)
|
local dest_stats = luv.fs_stat(dest)
|
||||||
local should_process = true
|
local should_process = true
|
||||||
if dest_stats then
|
if dest_stats then
|
||||||
local ans = vim.fn.input(dest..' already exists, overwrite ? y/n: ')
|
ans = vim.fn.input(dest..' already exists, overwrite ? y/n: ')
|
||||||
clear_prompt()
|
clear_prompt()
|
||||||
should_process = ans:match('^y')
|
should_process = ans:match('^y')
|
||||||
end
|
end
|
||||||
|
|
||||||
if should_process then
|
if should_process then
|
||||||
local success, msg = action_fn(entry.absolute_path, dest)
|
local success, errmsg = action_fn(entry.absolute_path, dest)
|
||||||
if not success then
|
if not success then
|
||||||
api.nvim_err_writeln('Could not '..action_type..' '..entry.absolute_path..' - '..msg)
|
api.nvim_err_writeln('Could not '..action_type..' '..entry.absolute_path..' - '..errmsg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,13 @@ M.Tree = {
|
|||||||
win_width = vim.g.lua_tree_width or 30,
|
win_width = vim.g.lua_tree_width or 30,
|
||||||
loaded = false,
|
loaded = false,
|
||||||
bufnr = nil,
|
bufnr = nil,
|
||||||
winnr = nil,
|
winnr = function()
|
||||||
|
for _, i in ipairs(api.nvim_list_wins()) do
|
||||||
|
if api.nvim_buf_get_name(api.nvim_win_get_buf(i)):match('.*/'..M.Tree.buf_name..'$') then
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
buf_options = {
|
buf_options = {
|
||||||
'noswapfile',
|
'noswapfile',
|
||||||
},
|
},
|
||||||
@@ -71,7 +77,7 @@ local function get_node_at_line(line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.get_node_at_cursor()
|
function M.get_node_at_cursor()
|
||||||
local cursor = api.nvim_win_get_cursor(M.Tree.winnr)
|
local cursor = api.nvim_win_get_cursor(M.Tree.winnr())
|
||||||
local line = cursor[1]
|
local line = cursor[1]
|
||||||
if line == 1 and M.Tree.cwd ~= "/" then
|
if line == 1 and M.Tree.cwd ~= "/" then
|
||||||
return { name = ".." }
|
return { name = ".." }
|
||||||
@@ -169,7 +175,7 @@ function M.set_index_and_redraw(fname)
|
|||||||
end
|
end
|
||||||
renderer.draw(M.Tree, reload)
|
renderer.draw(M.Tree, reload)
|
||||||
if index then
|
if index then
|
||||||
api.nvim_win_set_cursor(M.Tree.winnr, {index, 0})
|
api.nvim_win_set_cursor(M.Tree.winnr(), {index, 0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -246,23 +252,25 @@ local function create_win()
|
|||||||
api.nvim_command("wincmd "..window_opts.side)
|
api.nvim_command("wincmd "..window_opts.side)
|
||||||
api.nvim_command("vertical resize "..M.Tree.win_width)
|
api.nvim_command("vertical resize "..M.Tree.win_width)
|
||||||
|
|
||||||
M.Tree.winnr = api.nvim_get_current_win()
|
local winnr = api.nvim_get_current_win()
|
||||||
|
|
||||||
for opt, val in pairs(M.Tree.win_options) do
|
for opt, val in pairs(M.Tree.win_options) do
|
||||||
api.nvim_win_set_option(M.Tree.winnr, opt, val)
|
api.nvim_win_set_option(winnr, opt, val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.close()
|
function M.close()
|
||||||
api.nvim_win_close(M.Tree.winnr, true)
|
if #api.nvim_list_wins() == 1 then
|
||||||
M.Tree.winnr = nil
|
return vim.cmd ':q!'
|
||||||
|
end
|
||||||
|
api.nvim_win_close(M.Tree.winnr(), true)
|
||||||
M.Tree.bufnr = nil
|
M.Tree.bufnr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.open()
|
function M.open()
|
||||||
create_buf()
|
create_buf()
|
||||||
create_win()
|
create_win()
|
||||||
api.nvim_win_set_buf(M.Tree.winnr, M.Tree.bufnr)
|
api.nvim_win_set_buf(M.Tree.winnr(), M.Tree.bufnr)
|
||||||
|
|
||||||
for _, opt in pairs(M.Tree.buf_options) do
|
for _, opt in pairs(M.Tree.buf_options) do
|
||||||
api.nvim_command('setlocal '..opt)
|
api.nvim_command('setlocal '..opt)
|
||||||
@@ -276,12 +284,7 @@ function M.open()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.win_open()
|
function M.win_open()
|
||||||
for _, win in pairs(api.nvim_list_wins()) do
|
return M.Tree.winnr() ~= nil
|
||||||
if win == M.Tree.winnr then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.toggle_ignored()
|
function M.toggle_ignored()
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ function M.refresh_entries(entries, cwd)
|
|||||||
local change_prev
|
local change_prev
|
||||||
for _, e in ipairs(all) do
|
for _, e in ipairs(all) do
|
||||||
for _, name in ipairs(e.entries) do
|
for _, name in ipairs(e.entries) do
|
||||||
chang_prev = true
|
change_prev = true
|
||||||
if not named_entries[name] then
|
if not named_entries[name] then
|
||||||
local n = e.fn(cwd, name)
|
local n = e.fn(cwd, name)
|
||||||
if e.check(n.link_to, n.absolute_path) then
|
if e.check(n.link_to, n.absolute_path) then
|
||||||
@@ -141,10 +141,10 @@ function M.refresh_entries(entries, cwd)
|
|||||||
entries_idx[name] = idx
|
entries_idx[name] = idx
|
||||||
cached_entries[idx] = name
|
cached_entries[idx] = name
|
||||||
else
|
else
|
||||||
chang_prev = false
|
change_prev = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if chang_prev then prev = name end
|
if change_prev then prev = name end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ local get_padding = function(depth)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if vim.g.lua_tree_indent_markers == 1 then
|
if vim.g.lua_tree_indent_markers == 1 then
|
||||||
get_padding = function(depth, idx, tree, node, markers)
|
get_padding = function(depth, idx, tree, _, markers)
|
||||||
local padding = ""
|
local padding = ""
|
||||||
if depth ~= 0 then
|
if depth ~= 0 then
|
||||||
local rdepth = depth/2
|
local rdepth = depth/2
|
||||||
|
|||||||
Reference in New Issue
Block a user