updated neotree

pull/1708/head
Oluwatobi 1 year ago
parent 00ed47465d
commit 081d908c86

@ -1,115 +0,0 @@
require("neo-tree").setup({
cmd = "Neotree",
keys = {
{
"<leader>o",
function()
if vim.bo.filetype == "neo-tree" then
vim.cmd.wincmd "p"
else
vim.cmd.Neotree "focus"
end
end,
desc = "Toggle Explorer Focus"
},
{ "<C-n>", "<cmd>Neotree toggle<cr>", desc = "Toggle Explorer" }
},
init = function() vim.g.neo_tree_remove_legacy_commands = true end,
opts = {
auto_clean_after_session_restore = true,
close_if_last_window = true,
source_selector = {
winbar = true,
content_layout = "center",
},
commands = {
parent_or_close = function(state)
local node = state.tree:get_node()
if (node.type == "directory" or node:has_children()) and node:is_expanded() then
state.commands.toggle_node(state)
else
require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
end
end,
child_or_open = function(state)
local node = state.tree:get_node()
if node.type == "directory" or node:has_children() then
if not node:is_expanded() then -- if unexpanded, expand
state.commands.toggle_node(state)
else -- if expanded and has children, seleect the next child
require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1])
end
else -- if not a directory just open it
state.commands.open(state)
end
end,
copy_selector = function(state)
local node = state.tree:get_node()
local filepath = node:get_id()
local filename = node.name
local modify = vim.fn.fnamemodify
local results = {
e = { val = modify(filename, ":e"), msg = "Extension only" },
f = { val = filename, msg = "Filename" },
F = { val = modify(filename, ":r"), msg = "Filename w/o extension" },
h = { val = modify(filepath, ":~"), msg = "Path relative to Home" },
p = { val = modify(filepath, ":."), msg = "Path relative to CWD" },
P = { val = filepath, msg = "Absolute path" },
}
local messages = {
{ "\nChoose to copy to clipboard:\n", "Normal" },
}
for i, result in pairs(results) do
if result.val and result.val ~= "" then
vim.list_extend(messages, {
{ ("%s."):format(i), "Identifier" },
{ (" %s: "):format(result.msg) },
{ result.val, "String" },
{ "\n" },
})
end
end
vim.api.nvim_echo(messages, false, {})
local result = results[vim.fn.getcharstr()]
if result and result.val and result.val ~= "" then
vim.notify("Copied: " .. result.val)
vim.fn.setreg("+", result.val)
end
end,
},
window = {
width = 30,
mappings = {
["<space>"] = false, -- disable space until we figure out which-key disabling
["[b"] = "prev_source",
["]b"] = "next_source",
o = "open",
--[[ O = "system_open", ]]
h = "parent_or_close",
l = "child_or_open",
Y = "copy_selector",
},
},
filesystem = {
hijack_netrw_behavior = "open_current",
use_libuv_file_watcher = true,
follow_current_file = {
enabled = true, -- This will find and focus the file in the active buffer every time
-- -- the current file is changed while the tree is open.
leave_dirs_open = false, -- `false` closes auto expanded dirs, such as with `:Neotree reveal`
},
},
event_handlers = {
{
event = "neo_tree_buffer_enter",
handler = function(_)
vim.opt_local.signcolumn = "auto"
-- require("neo-tree").close_all()
end,
},
},
},
})

@ -32,6 +32,7 @@
"nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" },
"nvim-ts-autotag": { "branch": "main", "commit": "dc5e1687ab76ee02e0f11c5ce137f530b36e98b3" }, "nvim-ts-autotag": { "branch": "main", "commit": "dc5e1687ab76ee02e0f11c5ce137f530b36e98b3" },
"nvim-web-devicons": { "branch": "master", "commit": "5be6c4e685618b99c3210a69375b38a1202369b4" }, "nvim-web-devicons": { "branch": "master", "commit": "5be6c4e685618b99c3210a69375b38a1202369b4" },
"nvim-window-picker": { "branch": "main", "commit": "41cfaa428577c53552200a404ae9b3a0b5719706" },
"plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" },
"tailwind-tools.nvim": { "branch": "master", "commit": "7f1dda9ac3fb0460dfa4243656e8f00e36856385" }, "tailwind-tools.nvim": { "branch": "master", "commit": "7f1dda9ac3fb0460dfa4243656e8f00e36856385" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" },

@ -1,52 +1,70 @@
return { return {
"nvim-neo-tree/neo-tree.nvim", 'nvim-neo-tree/neo-tree.nvim',
branch = "v3.x", branch = 'v3.x',
dependencies = { dependencies = {
"nvim-lua/plenary.nvim", 'nvim-lua/plenary.nvim',
"nvim-tree/nvim-web-devicons", 'nvim-tree/nvim-web-devicons',
"MunifTanjim/nui.nvim", 'MunifTanjim/nui.nvim',
"3rd/image.nvim", '3rd/image.nvim',
{
's1n7ax/nvim-window-picker',
version = '2.*',
config = function()
require('window-picker').setup {
filter_rules = {
include_current_win = false,
autoselect_one = true,
bo = {
filetype = { 'neo-tree', 'neo-tree-popup', 'notify' },
buftype = { 'terminal', 'quickfix' },
},
}, },
cmd = "Neotree", }
end,
},
},
cmd = 'Neotree',
keys = { keys = {
{ {
"<leader>o", '<leader>o',
function() function()
if vim.bo.filetype == "neo-tree" then if vim.bo.filetype == 'neo-tree' then
vim.cmd.wincmd "p" vim.cmd.wincmd 'p'
else else
vim.cmd.Neotree "focus" vim.cmd.Neotree 'focus'
end end
end, end,
desc = "Toggle Explorer Focus" desc = 'Toggle Explorer Focus',
}, },
{ "<C-n>", "<cmd>Neotree toggle<cr>", desc = "Toggle Explorer" } { '<C-n>', '<cmd>Neotree toggle<cr>', desc = 'Toggle Explorer' },
}, },
init = function() vim.g.neo_tree_remove_legacy_commands = true end, init = function()
vim.g.neo_tree_remove_legacy_commands = true
end,
opts = { opts = {
auto_clean_after_session_restore = true, auto_clean_after_session_restore = true,
close_if_last_window = true, close_if_last_window = true,
source_selector = { source_selector = {
winbar = true, winbar = true,
content_layout = "center", content_layout = 'center',
}, },
commands = { commands = {
parent_or_close = function(state) parent_or_close = function(state)
local node = state.tree:get_node() local node = state.tree:get_node()
if (node.type == "directory" or node:has_children()) and node:is_expanded() then if (node.type == 'directory' or node:has_children()) and node:is_expanded() then
state.commands.toggle_node(state) state.commands.toggle_node(state)
else else
require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id()) require('neo-tree.ui.renderer').focus_node(state, node:get_parent_id())
end end
end, end,
child_or_open = function(state) child_or_open = function(state)
local node = state.tree:get_node() local node = state.tree:get_node()
if node.type == "directory" or node:has_children() then if node.type == 'directory' or node:has_children() then
if not node:is_expanded() then -- if unexpanded, expand if not node:is_expanded() then -- if unexpanded, expand
state.commands.toggle_node(state) state.commands.toggle_node(state)
else -- if expanded and has children, seleect the next child else -- if expanded and has children, seleect the next child
require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1]) require('neo-tree.ui.renderer').focus_node(state, node:get_child_ids()[1])
end end
else -- if not a directory just open it else -- if not a directory just open it
state.commands.open(state) state.commands.open(state)
@ -59,50 +77,50 @@ return {
local modify = vim.fn.fnamemodify local modify = vim.fn.fnamemodify
local results = { local results = {
e = { val = modify(filename, ":e"), msg = "Extension only" }, e = { val = modify(filename, ':e'), msg = 'Extension only' },
f = { val = filename, msg = "Filename" }, f = { val = filename, msg = 'Filename' },
F = { val = modify(filename, ":r"), msg = "Filename w/o extension" }, F = { val = modify(filename, ':r'), msg = 'Filename w/o extension' },
h = { val = modify(filepath, ":~"), msg = "Path relative to Home" }, h = { val = modify(filepath, ':~'), msg = 'Path relative to Home' },
p = { val = modify(filepath, ":."), msg = "Path relative to CWD" }, p = { val = modify(filepath, ':.'), msg = 'Path relative to CWD' },
P = { val = filepath, msg = "Absolute path" }, P = { val = filepath, msg = 'Absolute path' },
} }
local messages = { local messages = {
{ "\nChoose to copy to clipboard:\n", "Normal" }, { '\nChoose to copy to clipboard:\n', 'Normal' },
} }
for i, result in pairs(results) do for i, result in pairs(results) do
if result.val and result.val ~= "" then if result.val and result.val ~= '' then
vim.list_extend(messages, { vim.list_extend(messages, {
{ ("%s."):format(i), "Identifier" }, { ('%s.'):format(i), 'Identifier' },
{ (" %s: "):format(result.msg) }, { (' %s: '):format(result.msg) },
{ result.val, "String" }, { result.val, 'String' },
{ "\n" }, { '\n' },
}) })
end end
end end
vim.api.nvim_echo(messages, false, {}) vim.api.nvim_echo(messages, false, {})
local result = results[vim.fn.getcharstr()] local result = results[vim.fn.getcharstr()]
if result and result.val and result.val ~= "" then if result and result.val and result.val ~= '' then
vim.notify("Copied: " .. result.val) vim.notify('Copied: ' .. result.val)
vim.fn.setreg("+", result.val) vim.fn.setreg('+', result.val)
end end
end, end,
}, },
window = { window = {
width = 30, width = 30,
mappings = { mappings = {
["<space>"] = false, -- disable space until we figure out which-key disabling ['<space>'] = false, -- disable space until we figure out which-key disabling
["[b"] = "prev_source", ['[b'] = 'prev_source',
["]b"] = "next_source", [']b'] = 'next_source',
o = "open", o = 'open',
--[[ O = "system_open", ]] --[[ O = "system_open", ]]
h = "parent_or_close", h = 'parent_or_close',
l = "child_or_open", l = 'child_or_open',
Y = "copy_selector", Y = 'copy_selector',
}, },
}, },
filesystem = { filesystem = {
hijack_netrw_behavior = "open_current", hijack_netrw_behavior = 'open_current',
use_libuv_file_watcher = true, use_libuv_file_watcher = true,
follow_current_file = { follow_current_file = {
enabled = true, -- This will find and focus the file in the active buffer every time enabled = true, -- This will find and focus the file in the active buffer every time
@ -112,9 +130,9 @@ return {
}, },
event_handlers = { event_handlers = {
{ {
event = "neo_tree_buffer_enter", event = 'neo_tree_buffer_enter',
handler = function(_) handler = function(_)
vim.opt_local.signcolumn = "auto" vim.opt_local.signcolumn = 'auto'
-- require("neo-tree").close_all() -- require("neo-tree").close_all()
end, end,
}, },

Loading…
Cancel
Save