feat: close file info popup if on same node (#1054)
This commit is contained in:
committed by
GitHub
parent
b493e23ed7
commit
c25be06612
@@ -227,7 +227,7 @@ require'nvim-tree'.setup {
|
|||||||
- `W` will collapse the whole tree
|
- `W` will collapse the whole tree
|
||||||
- `S` will prompt the user to enter a path and then expands the tree to match the path
|
- `S` will prompt the user to enter a path and then expands the tree to match the path
|
||||||
- `.` will enter vim command mode with the file the cursor is on
|
- `.` will enter vim command mode with the file the cursor is on
|
||||||
- `C-k` will show file infos about the file under the cursor
|
- `C-k` will toggle a popup with file infos about the file under the cursor
|
||||||
|
|
||||||
### Settings
|
### Settings
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ local list = {
|
|||||||
{ key = "g?", action = "toggle_help" },
|
{ key = "g?", action = "toggle_help" },
|
||||||
{ key = "W", action = "collapse_all" },
|
{ key = "W", action = "collapse_all" },
|
||||||
{ key = "S", action = "search_node" },
|
{ key = "S", action = "search_node" },
|
||||||
{ key = "<C-k>", action = "show_file_info" },
|
{ key = "<C-k>", action = "toggle_file_info" },
|
||||||
{ key = ".", action = "run_file_command" }
|
{ key = ".", action = "run_file_command" }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ INFORMATIONS *nvim-tree-info*
|
|||||||
- `W` will collapse the whole tree
|
- `W` will collapse the whole tree
|
||||||
- `S` will prompt the user to enter a path and then expands the tree to match the path
|
- `S` will prompt the user to enter a path and then expands the tree to match the path
|
||||||
- `.` will enter vim command mode with the file the cursor is on
|
- `.` will enter vim command mode with the file the cursor is on
|
||||||
- `C-k` will show file infos about the file under the cursor
|
- `C-k` will toggle a popup with file infos about the file under the cursor
|
||||||
|
|
||||||
Defaults to:
|
Defaults to:
|
||||||
>
|
>
|
||||||
@@ -670,7 +670,7 @@ Defaults to:
|
|||||||
{ key = 'W', action = "collapse_all" },
|
{ key = 'W', action = "collapse_all" },
|
||||||
{ key = "S", action = "search_node" },
|
{ key = "S", action = "search_node" },
|
||||||
{ key = ".", action = "run_file_command" },
|
{ key = ".", action = "run_file_command" },
|
||||||
{ key = "<C-k>", action = "show_file_info" }
|
{ key = "<C-k>", action = "toggle_file_info" }
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
The `list` option in `view.mappings.list` is a table of
|
The `list` option in `view.mappings.list` is a table of
|
||||||
|
|||||||
@@ -20,11 +20,13 @@ local function get_formatted_lines(node)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local winnr = nil
|
local current_popup = nil
|
||||||
|
|
||||||
|
local function setup_window(node)
|
||||||
|
local lines = get_formatted_lines(node)
|
||||||
|
|
||||||
local function setup_window(lines)
|
|
||||||
local max_width = vim.fn.max(vim.tbl_map(function(n) return #n end, lines))
|
local max_width = vim.fn.max(vim.tbl_map(function(n) return #n end, lines))
|
||||||
winnr = a.nvim_open_win(0, false, {
|
local winnr = a.nvim_open_win(0, false, {
|
||||||
col = 1,
|
col = 1,
|
||||||
row = 1,
|
row = 1,
|
||||||
relative = "cursor",
|
relative = "cursor",
|
||||||
@@ -34,25 +36,36 @@ local function setup_window(lines)
|
|||||||
noautocmd = true,
|
noautocmd = true,
|
||||||
style = 'minimal'
|
style = 'minimal'
|
||||||
})
|
})
|
||||||
|
current_popup = {
|
||||||
|
winnr = winnr,
|
||||||
|
file_path = node.absolute_path
|
||||||
|
}
|
||||||
local bufnr = a.nvim_create_buf(false, true)
|
local bufnr = a.nvim_create_buf(false, true)
|
||||||
a.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
a.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||||
a.nvim_win_set_buf(winnr, bufnr)
|
a.nvim_win_set_buf(winnr, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.close_popup()
|
function M.close_popup()
|
||||||
if winnr ~= nil then
|
if current_popup ~= nil then
|
||||||
a.nvim_win_close(winnr, { force = true })
|
a.nvim_win_close(current_popup.winnr, { force = true })
|
||||||
vim.cmd "augroup NvimTreeRemoveFilePopup | au! CursorMoved | augroup END"
|
vim.cmd "augroup NvimTreeRemoveFilePopup | au! CursorMoved | augroup END"
|
||||||
|
|
||||||
winnr = nil
|
current_popup = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.show_file_info(node)
|
function M.toggle_file_info(node)
|
||||||
M.close_popup()
|
if current_popup ~= nil then
|
||||||
|
local is_same_node = current_popup.file_path == node.absolute_path
|
||||||
|
|
||||||
local lines = get_formatted_lines(node)
|
M.close_popup()
|
||||||
setup_window(lines)
|
|
||||||
|
if is_same_node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup_window(node)
|
||||||
|
|
||||||
vim.cmd [[
|
vim.cmd [[
|
||||||
augroup NvimTreeRemoveFilePopup
|
augroup NvimTreeRemoveFilePopup
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ local M = {
|
|||||||
{ key = 'W', action = "collapse_all" },
|
{ key = 'W', action = "collapse_all" },
|
||||||
{ key = "S", action = "search_node" },
|
{ key = "S", action = "search_node" },
|
||||||
{ key = ".", action = "run_file_command" },
|
{ key = ".", action = "run_file_command" },
|
||||||
{ key = "<C-k>", action = "show_file_info" }
|
{ key = "<C-k>", action = "toggle_file_info" }
|
||||||
},
|
},
|
||||||
custom_keypress_funcs = {},
|
custom_keypress_funcs = {},
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ local keypress_funcs = {
|
|||||||
rename = require'nvim-tree.actions.rename-file'.fn(false),
|
rename = require'nvim-tree.actions.rename-file'.fn(false),
|
||||||
run_file_command = require'nvim-tree.actions.run-command'.run_file_command,
|
run_file_command = require'nvim-tree.actions.run-command'.run_file_command,
|
||||||
search_node = require'nvim-tree.actions.search-node'.fn,
|
search_node = require'nvim-tree.actions.search-node'.fn,
|
||||||
show_file_info = require'nvim-tree.actions.file-popup'.show_file_info,
|
toggle_file_info = require'nvim-tree.actions.file-popup'.toggle_file_info,
|
||||||
system_open = require'nvim-tree.actions.system-open'.fn,
|
system_open = require'nvim-tree.actions.system-open'.fn,
|
||||||
toggle_dotfiles = require"nvim-tree.actions.toggles".dotfiles,
|
toggle_dotfiles = require"nvim-tree.actions.toggles".dotfiles,
|
||||||
toggle_help = require"nvim-tree.actions.toggles".help,
|
toggle_help = require"nvim-tree.actions.toggles".help,
|
||||||
|
|||||||
Reference in New Issue
Block a user