From cdbd7daf29db09e58a4ddc181c1be91c07184f4e Mon Sep 17 00:00:00 2001 From: Richard Li <38484873+chomosuke@users.noreply.github.com> Date: Tue, 3 Jan 2023 15:11:14 +1300 Subject: [PATCH 1/8] fix(#1878): nvim frozen on no name buffer when modified.enable (#1879) --- lua/nvim-tree/modified.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree/modified.lua b/lua/nvim-tree/modified.lua index eff1a18e9ed..51025e1b22f 100644 --- a/lua/nvim-tree/modified.lua +++ b/lua/nvim-tree/modified.lua @@ -9,10 +9,16 @@ function M.reload() local bufs = vim.fn.getbufinfo { bufmodified = true, buflisted = true } for _, buf in pairs(bufs) do local path = buf.name - M._record[path] = true - while path ~= vim.fn.getcwd() and path ~= "/" do - path = vim.fn.fnamemodify(path, ":h") - M._record[path] = true + if path ~= "" then -- not a [No Name] buffer + -- mark all the parent as modified as well + while + M._record[path] ~= true + -- no need to keep going if already recorded + -- This also prevents an infinite loop + do + M._record[path] = true + path = vim.fn.fnamemodify(path, ":h") + end end end end From bac962caf472a4404ed3ce1ba2fcaf32f8002951 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 3 Jan 2023 13:13:49 +1100 Subject: [PATCH 2/8] feat(api): add api.config.mappings.active, api.config.mappings.default (#1876) * feat(api): add config.mappings.current and config.mappings.default * feat(api): add config.mappings.current and config.mappings.default * feat(api): add config.mappings.current and config.mappings.default --- doc/nvim-tree-lua.txt | 14 ++++++++++++++ lua/nvim-tree/actions/init.lua | 12 ++++++++++++ lua/nvim-tree/api.lua | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 2dac973970a..fae1f4fd197 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1335,6 +1335,20 @@ exists. - navigate.prev - navigate.select +api.config.mappings.active() *nvim-tree.api.config.mappings.active()* + Retrieve a clone of the currently active mappings: + |nvim-tree-default-mappings| with |nvim-tree.view.mappings| applied. + Changing the active mappings will require a call to |nvim-tree-setup| + + Return: ~ + (table) as per |nvim-tree.view.mappings.list| + +api.config.mappings.default() *nvim-tree.api.config.mappings.default()* + Retrieve a clone of the default mappings: |nvim-tree-default-mappings| + + Return: ~ + (table) as per |nvim-tree.view.mappings.list| + ============================================================================== 6. MAPPINGS *nvim-tree-mappings* diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index b1f12c9ab2f..7a9fad21e79 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -399,6 +399,18 @@ local DEFAULT_MAPPING_CONFIG = { list = {}, } +--- clone default for the user +--- @return table +function M.default_mappings_clone() + return vim.deepcopy(DEFAULT_MAPPINGS) +end + +--- clone active for the user +--- @return table +function M.active_mappings_clone() + return vim.deepcopy(M.mappings) +end + function M.setup(opts) require("nvim-tree.actions.fs.trash").setup(opts) require("nvim-tree.actions.node.system-open").setup(opts) diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 515d9ffd3d6..e40bfcd6729 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -6,6 +6,7 @@ local Api = { fs = { copy = {} }, git = {}, live_filter = {}, + config = { mappings = {} }, } local function inject_node(f) @@ -127,4 +128,7 @@ Api.marks.navigate.next = require("nvim-tree.marks.navigation").next Api.marks.navigate.prev = require("nvim-tree.marks.navigation").prev Api.marks.navigate.select = require("nvim-tree.marks.navigation").select +Api.config.mappings.active = require("nvim-tree.actions").active_mappings_clone +Api.config.mappings.default = require("nvim-tree.actions").default_mappings_clone + return Api From fdfe70e1cf2a9cc3d65e04698e374667bd2685c6 Mon Sep 17 00:00:00 2001 From: Telman Babayev Date: Thu, 5 Jan 2023 13:10:08 +0400 Subject: [PATCH 3/8] Implement turning off y/n prompt for file deletion --- lua/nvim-tree.lua | 1 + lua/nvim-tree/actions/fs/remove-file.lua | 55 ++++++++++++++---------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 8c11ee33221..52dd8e1a8c2 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -495,6 +495,7 @@ local function setup_autocommands(opts) end local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS + file_deletion_confirmation = true, auto_reload_on_write = true, disable_netrw = false, hijack_cursor = false, diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index ff2d4630041..b250db1b616 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -73,36 +73,47 @@ function M.fn(node) if node.name == ".." then return end - local prompt_select = "Remove " .. node.name .. " ?" - local prompt_input = prompt_select .. " y/n: " - lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short) - utils.clear_prompt() - if item_short == "y" then - if node.nodes ~= nil and not node.link_to then - local success = remove_dir(node.absolute_path) - if not success then - return notify.error("Could not remove " .. node.name) - end - events._dispatch_folder_removed(node.absolute_path) - else - local success = vim.loop.fs_unlink(node.absolute_path) - if not success then - return notify.error("Could not remove " .. node.name) - end - events._dispatch_file_removed(node.absolute_path) - clear_buffer(node.absolute_path) + + local function do_remove() + if node.nodes ~= nil and not node.link_to then + local success = remove_dir(node.absolute_path) + if not success then + return notify.error("Could not remove " .. node.name) end - notify.info(node.absolute_path .. " was properly removed.") - if M.enable_reload then - require("nvim-tree.actions.reloaders.reloaders").reload_explorer() + events._dispatch_folder_removed(node.absolute_path) + else + local success = vim.loop.fs_unlink(node.absolute_path) + if not success then + return notify.error("Could not remove " .. node.name) end + events._dispatch_file_removed(node.absolute_path) + clear_buffer(node.absolute_path) end - end) + notify.info(node.absolute_path .. " was properly removed.") + if M.enable_reload then + require("nvim-tree.actions.reloaders.reloaders").reload_explorer() + end + end + + + if M.file_deletion_confirmation then + local prompt_select = "Remove " .. node.name .. " ?" + local prompt_input = prompt_select .. " y/n: " + lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short) + utils.clear_prompt() + if item_short == "y" then + do_remove() + end + end) + else + do_remove() + end end function M.setup(opts) M.enable_reload = not opts.filesystem_watchers.enable M.close_window = opts.actions.remove_file.close_window + M.file_deletion_confirmation = opts.file_deletion_confirmation end return M From 2eb915dd4a8d6f7939c347b639a2ca10d1f72b1b Mon Sep 17 00:00:00 2001 From: Telman Babayev Date: Sat, 7 Jan 2023 21:59:19 +0400 Subject: [PATCH 4/8] Refactor different prompt configs to single ui table --- lua/nvim-tree.lua | 6 ++++++ lua/nvim-tree/actions/fs/remove-file.lua | 5 +++-- lua/nvim-tree/actions/fs/trash.lua | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 52dd8e1a8c2..2ed2be0bcba 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -495,6 +495,12 @@ local function setup_autocommands(opts) end local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS + ui = { + confirm = { + node_deletion = true, + trash = true, + }, + }, file_deletion_confirmation = true, auto_reload_on_write = true, disable_netrw = false, diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index b250db1b616..dd70a74821f 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -96,7 +96,7 @@ function M.fn(node) end - if M.file_deletion_confirmation then + if M.config.ui.confirm.node_deletion then local prompt_select = "Remove " .. node.name .. " ?" local prompt_input = prompt_select .. " y/n: " lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short) @@ -111,9 +111,10 @@ function M.fn(node) end function M.setup(opts) + M.config = {} + M.config.ui = opts.ui or {} M.enable_reload = not opts.filesystem_watchers.enable M.close_window = opts.actions.remove_file.close_window - M.file_deletion_confirmation = opts.file_deletion_confirmation end return M diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 76ea2aa4aa7..18588095720 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -87,7 +87,7 @@ function M.fn(node) end end - if M.config.trash.require_confirm then + if M.config.ui.confirm.trash then local prompt_select = "Trash " .. node.name .. " ?" local prompt_input = prompt_select .. " y/n: " lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short) @@ -103,7 +103,7 @@ end function M.setup(opts) M.config = {} - M.config.trash = opts.trash or {} + M.config.ui = opts.ui or {} M.enable_reload = not opts.filesystem_watchers.enable end From cf36d357158deeda8162c06ed672e29ba0d6ae64 Mon Sep 17 00:00:00 2001 From: Telman Babayev Date: Sat, 7 Jan 2023 22:11:02 +0400 Subject: [PATCH 5/8] Remove unused fields --- lua/nvim-tree.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 2ed2be0bcba..3292a9f05b8 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -501,7 +501,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS trash = true, }, }, - file_deletion_confirmation = true, auto_reload_on_write = true, disable_netrw = false, hijack_cursor = false, @@ -705,7 +704,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, trash = { cmd = "gio trash", - require_confirm = true, }, live_filter = { prefix = "[FILTER]: ", From 46411f60c6ddfe118664fb53d6abb583065b883c Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 8 Jan 2023 12:19:48 +1100 Subject: [PATCH 6/8] add ui.confirm doc, format/tidy --- doc/nvim-tree-lua.txt | 21 ++++++++++++++++++++- lua/nvim-tree.lua | 12 ++++++------ lua/nvim-tree/actions/fs/remove-file.lua | 7 +++---- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index fae1f4fd197..93d023a1532 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -374,7 +374,6 @@ Subsequent calls to setup will replace the previous configuration. }, trash = { cmd = "gio trash", - require_confirm = true, }, live_filter = { prefix = "[FILTER]: ", @@ -390,6 +389,12 @@ Subsequent calls to setup will replace the previous configuration. notify = { threshold = vim.log.levels.INFO, }, + ui = { + confirm = { + remove = true, + trash = true, + }, + }, log = { enable = false, truncate = false, @@ -1146,6 +1151,20 @@ Configuration for notification. `INFO:` information only e.g. file copy path confirmation. `DEBUG:` not used. +*nvim-tree.ui* +General UI configuration. + + *nvim-tree.ui.confirm* + Confirmation prompts. + + *nvim-tree.ui.confirm.remove* + Prompt before removing. + Type: `boolean`, Default: `true` + + *nvim-tree.ui.confirm.trash* (previously `trash.require_confirm`) + Prompt before trashing. + Type: `boolean`, Default: `true` + *nvim-tree.log* Configuration for diagnostic logging. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 3292a9f05b8..883bc5cc511 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -495,12 +495,6 @@ local function setup_autocommands(opts) end local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS - ui = { - confirm = { - node_deletion = true, - trash = true, - }, - }, auto_reload_on_write = true, disable_netrw = false, hijack_cursor = false, @@ -719,6 +713,12 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS notify = { threshold = vim.log.levels.INFO, }, + ui = { + confirm = { + remove = true, + trash = true, + }, + }, log = { enable = false, truncate = false, diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index dd70a74821f..9acf6c516b0 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -95,8 +95,7 @@ function M.fn(node) end end - - if M.config.ui.confirm.node_deletion then + if M.config.ui.confirm.remove then local prompt_select = "Remove " .. node.name .. " ?" local prompt_input = prompt_select .. " y/n: " lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short) @@ -111,8 +110,8 @@ function M.fn(node) end function M.setup(opts) - M.config = {} - M.config.ui = opts.ui or {} + M.config = {} + M.config.ui = opts.ui or {} M.enable_reload = not opts.filesystem_watchers.enable M.close_window = opts.actions.remove_file.close_window end From 4fd9957b5e46c67b0d8f4fdba63e983cd7170baa Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 8 Jan 2023 12:24:10 +1100 Subject: [PATCH 7/8] trash.require_confirm -> ui.confirm.trash --- doc/nvim-tree-lua.txt | 4 ---- lua/nvim-tree/legacy.lua | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 93d023a1532..09ff827a350 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -998,10 +998,6 @@ Configuration options for trashing. The default is shipped with glib2 which is a common linux package. Type: `string`, Default: `"gio trash"` - *nvim-tree.trash.require_confirm* - Show a prompt before trashing takes place. - Type: `boolean`, Default: `true` - *nvim-tree.actions* Configuration for various actions. diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 0bddb6a2f0c..2b0eee06178 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -27,6 +27,9 @@ local function refactored(opts) -- 2023/01/01 utils.move_missing_val(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true) + + -- 2023/01/08 + utils.move_missing_val(opts, "trash", "require_confirm", opts, "ui.confirm", "trash", true) end local function removed(opts) From 32ac2cd1675b813187e9e4968c3cca701788ec59 Mon Sep 17 00:00:00 2001 From: Telman Babayev Date: Sun, 8 Jan 2023 09:18:43 +0400 Subject: [PATCH 8/8] Fix nil value trash field --- lua/nvim-tree/actions/fs/trash.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/actions/fs/trash.lua b/lua/nvim-tree/actions/fs/trash.lua index 18588095720..ea38511a843 100644 --- a/lua/nvim-tree/actions/fs/trash.lua +++ b/lua/nvim-tree/actions/fs/trash.lua @@ -32,8 +32,8 @@ function M.fn(node) if M.config.trash.cmd == nil then M.config.trash.cmd = "trash" end - if M.config.trash.require_confirm == nil then - M.config.trash.require_confirm = true + if M.config.ui.confirm.trash == nil then + M.config.ui.confirm.trash = true end else notify.warn "Trash is currently a UNIX only feature!" @@ -104,6 +104,7 @@ end function M.setup(opts) M.config = {} M.config.ui = opts.ui or {} + M.config.trash = opts.trash or {} M.enable_reload = not opts.filesystem_watchers.enable end