From 081d908c8662f4c4838c8e77970afa9955c9aa4b Mon Sep 17 00:00:00 2001 From: Oluwatobi Date: Thu, 1 Aug 2024 18:08:32 +0100 Subject: [PATCH] updated neotree --- after/plugin/neo-tree.lua | 115 -------------------------------------- lazy-lock.json | 1 + lua/plugins/neo-tree.lua | 114 +++++++++++++++++++++---------------- 3 files changed, 67 insertions(+), 163 deletions(-) delete mode 100644 after/plugin/neo-tree.lua diff --git a/after/plugin/neo-tree.lua b/after/plugin/neo-tree.lua deleted file mode 100644 index bfdf50ad..00000000 --- a/after/plugin/neo-tree.lua +++ /dev/null @@ -1,115 +0,0 @@ -require("neo-tree").setup({ - cmd = "Neotree", - keys = { - { - "o", - function() - if vim.bo.filetype == "neo-tree" then - vim.cmd.wincmd "p" - else - vim.cmd.Neotree "focus" - end - end, - desc = "Toggle Explorer Focus" - }, - { "", "Neotree toggle", 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 = { - [""] = 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, - }, - }, - }, -}) diff --git a/lazy-lock.json b/lazy-lock.json index e49fd86e..8085bfce 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -32,6 +32,7 @@ "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" }, "nvim-ts-autotag": { "branch": "main", "commit": "dc5e1687ab76ee02e0f11c5ce137f530b36e98b3" }, "nvim-web-devicons": { "branch": "master", "commit": "5be6c4e685618b99c3210a69375b38a1202369b4" }, + "nvim-window-picker": { "branch": "main", "commit": "41cfaa428577c53552200a404ae9b3a0b5719706" }, "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, "tailwind-tools.nvim": { "branch": "master", "commit": "7f1dda9ac3fb0460dfa4243656e8f00e36856385" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, diff --git a/lua/plugins/neo-tree.lua b/lua/plugins/neo-tree.lua index 815d1ede..9fba323e 100644 --- a/lua/plugins/neo-tree.lua +++ b/lua/plugins/neo-tree.lua @@ -1,52 +1,70 @@ return { - "nvim-neo-tree/neo-tree.nvim", - branch = "v3.x", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-tree/nvim-web-devicons", - "MunifTanjim/nui.nvim", - "3rd/image.nvim", + 'nvim-neo-tree/neo-tree.nvim', + branch = 'v3.x', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + 'MunifTanjim/nui.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' }, + }, + }, + } + end, }, - cmd = "Neotree", + }, + cmd = 'Neotree', keys = { { - "o", + 'o', function() - if vim.bo.filetype == "neo-tree" then - vim.cmd.wincmd "p" + if vim.bo.filetype == 'neo-tree' then + vim.cmd.wincmd 'p' else - vim.cmd.Neotree "focus" + vim.cmd.Neotree 'focus' end end, - desc = "Toggle Explorer Focus" + desc = 'Toggle Explorer Focus', }, - { "", "Neotree toggle", desc = "Toggle Explorer" } + { '', 'Neotree toggle', 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 = { auto_clean_after_session_restore = true, close_if_last_window = true, source_selector = { winbar = true, - content_layout = "center", + 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 + 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()) + 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 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]) + 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) @@ -59,62 +77,62 @@ return { 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" }, + 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" }, + { '\nChoose to copy to clipboard:\n', 'Normal' }, } 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, { - { ("%s."):format(i), "Identifier" }, - { (" %s: "):format(result.msg) }, - { result.val, "String" }, - { "\n" }, + { ('%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) + 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 = { - [""] = false, -- disable space until we figure out which-key disabling - ["[b"] = "prev_source", - ["]b"] = "next_source", - o = "open", + [''] = 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", + h = 'parent_or_close', + l = 'child_or_open', + Y = 'copy_selector', }, }, filesystem = { - hijack_netrw_behavior = "open_current", + 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 + 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` + leave_dirs_open = false, -- `false` closes auto expanded dirs, such as with `:Neotree reveal` }, }, event_handlers = { { - event = "neo_tree_buffer_enter", + event = 'neo_tree_buffer_enter', handler = function(_) - vim.opt_local.signcolumn = "auto" + vim.opt_local.signcolumn = 'auto' -- require("neo-tree").close_all() end, },