Merge branch 'master' into chore/action_cb_help_poc

This commit is contained in:
Alexander Courtis
2022-09-04 13:09:50 +10:00
23 changed files with 517 additions and 148 deletions

View File

@@ -27,12 +27,20 @@ function M.fn(fname)
local line = core.get_nodes_starting_line()
local absolute_paths_searched = {}
local found = Iterator.builder(core.get_explorer().nodes)
:matcher(function(node)
return node.absolute_path == fname_real or node.link_to == fname_real
end)
:applier(function(node)
line = line + 1
if vim.tbl_contains(absolute_paths_searched, node.absolute_path) then
return
end
table.insert(absolute_paths_searched, node.absolute_path)
local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator)
local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator)

View File

@@ -7,42 +7,54 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn
local M = {}
local function search(dir, input_path)
local path, name, stat, handle, _
local function search(search_dir, input_path)
local realpaths_searched = {}
if not dir then
if not search_dir then
return
end
handle, _ = uv.fs_scandir(dir)
if not handle then
return
end
local function iter(dir)
local realpath, path, name, stat, handle, _
name, _ = uv.fs_scandir_next(handle)
while name do
path = dir .. "/" .. name
stat, _ = uv.fs_stat(path)
if not stat then
break
handle, _ = uv.fs_scandir(dir)
if not handle then
return
end
if not filters.should_ignore(path) then
if string.find(path, "/" .. input_path .. "$") then
return path
end
if stat.type == "directory" then
path = search(path, input_path)
if path then
return path
end
end
realpath, _ = uv.fs_realpath(dir)
if not realpath or vim.tbl_contains(realpaths_searched, realpath) then
return
end
table.insert(realpaths_searched, realpath)
name, _ = uv.fs_scandir_next(handle)
while name do
path = dir .. "/" .. name
stat, _ = uv.fs_stat(path)
if not stat then
break
end
if not filters.should_ignore(path) then
if string.find(path, "/" .. input_path .. "$") then
return path
end
if stat.type == "directory" then
path = iter(path)
if path then
return path
end
end
end
name, _ = uv.fs_scandir_next(handle)
end
end
return iter(search_dir)
end
function M.fn()

View File

@@ -108,7 +108,7 @@ function M.fn(node)
end
-- INFO: defer needed when reload is automatic (watchers)
vim.defer_fn(function()
utils.focus_file(new_file_path)
utils.focus_file(utils.path_remove_trailing(new_file_path))
end, 150)
end)
end

View File

@@ -3,10 +3,15 @@ local luv = vim.loop
local utils = require "nvim-tree.utils"
local events = require "nvim-tree.events"
local view = require "nvim-tree.view"
local M = {}
local function close_windows(windows)
if view.View.float.enable and #a.nvim_list_wins() == 1 then
return
end
for _, window in ipairs(windows) do
if a.nvim_win_is_valid(window) then
a.nvim_win_close(window, true)
@@ -18,11 +23,13 @@ local function clear_buffer(absolute_path)
local bufs = vim.fn.getbufinfo { bufloaded = 1, buflisted = 1 }
for _, buf in pairs(bufs) do
if buf.name == absolute_path then
if buf.hidden == 0 and #bufs > 1 then
if buf.hidden == 0 and (#bufs > 1 or view.View.float.enable) then
local winnr = a.nvim_get_current_win()
a.nvim_set_current_win(buf.windows[1])
vim.cmd ":bn"
a.nvim_set_current_win(winnr)
if not view.View.float.enable then
a.nvim_set_current_win(winnr)
end
end
a.nvim_buf_delete(buf.bufnr, { force = true })
if M.close_window then

View File

@@ -390,6 +390,7 @@ local DEFAULT_MAPPING_CONFIG = {
function M.setup(opts)
require("nvim-tree.actions.fs.trash").setup(opts)
require("nvim-tree.actions.node.system-open").setup(opts)
require("nvim-tree.actions.node.file-popup").setup(opts)
require("nvim-tree.actions.node.open-file").setup(opts)
require("nvim-tree.actions.root.change-dir").setup(opts)
require("nvim-tree.actions.fs.create-file").setup(opts)

View File

@@ -28,16 +28,13 @@ local function setup_window(node)
local max_width = vim.fn.max(vim.tbl_map(function(n)
return #n
end, lines))
local winnr = a.nvim_open_win(0, false, {
col = 1,
row = 1,
relative = "cursor",
local open_win_config = vim.tbl_extend("force", M.open_win_config, {
width = max_width + 1,
height = #lines,
border = "shadow",
noautocmd = true,
style = "minimal",
zindex = 60,
})
local winnr = a.nvim_open_win(0, false, open_win_config)
current_popup = {
winnr = winnr,
file_path = node.absolute_path,
@@ -78,4 +75,8 @@ function M.toggle_file_info(node)
})
end
function M.setup(opts)
M.open_win_config = opts.actions.file_popup.open_win_config
end
return M

View File

@@ -280,7 +280,7 @@ function M.fn(mode, filename)
end
function M.setup(opts)
M.quit_on_open = opts.actions.open_file.quit_on_open
M.quit_on_open = opts.actions.open_file.quit_on_open or opts.view.float.enable
M.resize_window = opts.actions.open_file.resize_window
if opts.actions.open_file.window_picker.chars then
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()