Merge pull request #61 from kyazdani42/fix/window-handling

Fix/window handling
This commit is contained in:
Kiyan Yazdani
2020-07-23 11:41:37 +02:00
committed by GitHub
4 changed files with 25 additions and 22 deletions

View File

@@ -129,7 +129,7 @@ local function do_copy(source, destination)
luv.fs_mkdir(destination, source_stats.mode)
while true do
local name, t = luv.fs_scandir_next(handle)
local name, _ = luv.fs_scandir_next(handle)
if not name then break end
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 should_process = true
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()
should_process = ans:match('^y')
end
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
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

View File

@@ -19,7 +19,13 @@ M.Tree = {
win_width = vim.g.lua_tree_width or 30,
loaded = false,
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 = {
'noswapfile',
},
@@ -71,7 +77,7 @@ local function get_node_at_line(line)
end
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]
if line == 1 and M.Tree.cwd ~= "/" then
return { name = ".." }
@@ -169,7 +175,7 @@ function M.set_index_and_redraw(fname)
end
renderer.draw(M.Tree, reload)
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
@@ -246,23 +252,25 @@ local function create_win()
api.nvim_command("wincmd "..window_opts.side)
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
api.nvim_win_set_option(M.Tree.winnr, opt, val)
api.nvim_win_set_option(winnr, opt, val)
end
end
function M.close()
api.nvim_win_close(M.Tree.winnr, true)
M.Tree.winnr = nil
if #api.nvim_list_wins() == 1 then
return vim.cmd ':q!'
end
api.nvim_win_close(M.Tree.winnr(), true)
M.Tree.bufnr = nil
end
function M.open()
create_buf()
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
api.nvim_command('setlocal '..opt)
@@ -276,12 +284,7 @@ function M.open()
end
function M.win_open()
for _, win in pairs(api.nvim_list_wins()) do
if win == M.Tree.winnr then
return true
end
end
return false
return M.Tree.winnr() ~= nil
end
function M.toggle_ignored()

View File

@@ -129,7 +129,7 @@ function M.refresh_entries(entries, cwd)
local change_prev
for _, e in ipairs(all) do
for _, name in ipairs(e.entries) do
chang_prev = true
change_prev = true
if not named_entries[name] then
local n = e.fn(cwd, name)
if e.check(n.link_to, n.absolute_path) then
@@ -141,10 +141,10 @@ function M.refresh_entries(entries, cwd)
entries_idx[name] = idx
cached_entries[idx] = name
else
chang_prev = false
change_prev = false
end
end
if chang_prev then prev = name end
if change_prev then prev = name end
end
end
end

View File

@@ -92,7 +92,7 @@ local get_padding = function(depth)
end
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 = ""
if depth ~= 0 then
local rdepth = depth/2