From 34a5b70bac19804bd9fbcab3ea091ecf31dc00d5 Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Wed, 30 Nov 2022 15:07:14 +0000 Subject: [PATCH 01/22] relative rename action --- lua/nvim-tree/actions/dispatch.lua | 1 + lua/nvim-tree/actions/fs/rename-file.lua | 30 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 44eff9834b0..994f1b0461a 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -25,6 +25,7 @@ local Actions = { trash = require("nvim-tree.actions.fs.trash").fn, remove = require("nvim-tree.actions.fs.remove-file").fn, rename = require("nvim-tree.actions.fs.rename-file").fn(false), + relative_rename = require("nvim-tree.actions.fs.rename-file").fn(false, true), -- Movements in tree close_node = require("nvim-tree.actions.moves.parent").fn(true), diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 3ef08b0d268..ca22e9cbf94 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -24,7 +24,7 @@ function M.rename(node, to) events._dispatch_node_renamed(node.absolute_path, to) end -function M.fn(with_sub) +function M.fn(with_sub, relative_rename) return function(node) node = lib.get_last_group_node(node) if node.name == ".." then @@ -32,9 +32,31 @@ function M.fn(with_sub) end local namelen = node.name:len() - local abs_path = with_sub and node.absolute_path:sub(0, namelen * -1 - 1) or node.absolute_path + local abs_directory = node.absolute_path:sub(0, namelen * -1 - 1) + local default_path, prepend, append + if relative_rename then + local filename = node.absolute_path:sub(abs_directory:len() + 1) + local extension_index = filename:find("%.") or -1 + if extension_index > -1 then + default_path = filename:sub(0, extension_index -1) + append = filename:sub(extension_index) + else + default_path = filename + append = "" + end + prepend = abs_directory + print(filename .. "|" .. (extension_index or "na") .. "|" .. prepend .. "|" ..append) + else + prepend = "" + append = "" + if with_sub then + default_path = abs_directory + else + default_path = node.absolute_path + end + end - local input_opts = { prompt = "Rename to ", default = abs_path, completion = "file" } + local input_opts = { prompt = "Rename to ", default = default_path, completion = "file" } vim.ui.input(input_opts, function(new_file_path) utils.clear_prompt() @@ -42,7 +64,7 @@ function M.fn(with_sub) return end - M.rename(node, new_file_path) + M.rename(node, prepend .. new_file_path .. append) if M.enable_reload then require("nvim-tree.actions.reloaders.reloaders").reload_explorer() end From 2646bfa5e2b869d90d32da1ce1565db223d15acd Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Wed, 30 Nov 2022 15:22:43 +0000 Subject: [PATCH 02/22] =?UTF-8?q?=F0=9F=94=A5=20remove=20debug=20print=20s?= =?UTF-8?q?tatement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/nvim-tree/actions/fs/rename-file.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index ca22e9cbf94..6f297a29cb6 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -45,7 +45,6 @@ function M.fn(with_sub, relative_rename) append = "" end prepend = abs_directory - print(filename .. "|" .. (extension_index or "na") .. "|" .. prepend .. "|" ..append) else prepend = "" append = "" From 9dbef889079d2d69081d8bc90430ac36126a413a Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 3 Dec 2022 16:29:53 +0000 Subject: [PATCH 03/22] =?UTF-8?q?=F0=9F=90=9B=20better=20handling=20of=20d?= =?UTF-8?q?ot=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also pickout extension in filename with more one dot --- lua/nvim-tree/actions/fs/rename-file.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 6f297a29cb6..8e8367f9edb 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -36,8 +36,8 @@ function M.fn(with_sub, relative_rename) local default_path, prepend, append if relative_rename then local filename = node.absolute_path:sub(abs_directory:len() + 1) - local extension_index = filename:find("%.") or -1 - if extension_index > -1 then + local extension_index = filename:find("%.[^%.]*$") or -1 + if extension_index > 1 then default_path = filename:sub(0, extension_index -1) append = filename:sub(extension_index) else From af57e87df598b4ea594fcc3db8eabf14d37c871a Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 3 Dec 2022 16:30:55 +0000 Subject: [PATCH 04/22] =?UTF-8?q?=F0=9F=94=A7=20keymap=20e=20for=20relativ?= =?UTF-8?q?e-rename=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/nvim-tree/actions/init.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index f42875f92ed..1f8fa1b6ce5 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -121,6 +121,11 @@ local DEFAULT_MAPPINGS = { action = "full_rename", desc = "rename a file and omit the filename on input", }, + { + key = "e", + action = "relative_rename", + desc = "rename base name with changing directory or extension", + }, { key = "x", action = "cut", From 470132e3e5ebc137aa501b09618c057514525e60 Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 3 Dec 2022 16:38:39 +0000 Subject: [PATCH 05/22] =?UTF-8?q?=F0=9F=93=9D=20update=20help=20with=20rel?= =?UTF-8?q?ative-rename=20mapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/nvim-tree-lua.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index f7eb96f6163..0d9a6fc7d8c 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1328,6 +1328,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings `D` trash trash a file via |trash| option `r` rename rename a file `` full_rename rename a file and omit the filename on input +`e` relative_rename rename base name with changing directory or extension `x` cut add/remove file/directory to cut clipboard `c` copy add/remove file/directory to copy clipboard `p` paste paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation @@ -1377,6 +1378,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings { key = "D", action = "trash" }, { key = "r", action = "rename" }, { key = "", action = "full_rename" }, + { key = "e", action = "relative_rename" }, { key = "x", action = "cut" }, { key = "c", action = "copy" }, { key = "p", action = "paste" }, From 47312e0496f9b44bb5cbd8b454fc97bc04991177 Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 3 Dec 2022 16:55:40 +0000 Subject: [PATCH 06/22] =?UTF-8?q?=E2=9C=A8=20add=20API=20for=20rename=5Fre?= =?UTF-8?q?lative?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/nvim-tree-lua.txt | 4 ++-- lua/nvim-tree/actions/dispatch.lua | 2 +- lua/nvim-tree/actions/init.lua | 2 +- lua/nvim-tree/api.lua | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 0d9a6fc7d8c..a0ad65096f2 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1328,7 +1328,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings `D` trash trash a file via |trash| option `r` rename rename a file `` full_rename rename a file and omit the filename on input -`e` relative_rename rename base name with changing directory or extension +`e` rename_relative rename base name with changing directory or extension `x` cut add/remove file/directory to cut clipboard `c` copy add/remove file/directory to copy clipboard `p` paste paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation @@ -1378,7 +1378,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings { key = "D", action = "trash" }, { key = "r", action = "rename" }, { key = "", action = "full_rename" }, - { key = "e", action = "relative_rename" }, + { key = "e", action = "rename_relative" }, { key = "x", action = "cut" }, { key = "c", action = "copy" }, { key = "p", action = "paste" }, diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 994f1b0461a..1e7c6337a8c 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -25,7 +25,7 @@ local Actions = { trash = require("nvim-tree.actions.fs.trash").fn, remove = require("nvim-tree.actions.fs.remove-file").fn, rename = require("nvim-tree.actions.fs.rename-file").fn(false), - relative_rename = require("nvim-tree.actions.fs.rename-file").fn(false, true), + rename_relative = require("nvim-tree.actions.fs.rename-file").fn(false, true), -- Movements in tree close_node = require("nvim-tree.actions.moves.parent").fn(true), diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index 1f8fa1b6ce5..f5384e44314 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -123,7 +123,7 @@ local DEFAULT_MAPPINGS = { }, { key = "e", - action = "relative_rename", + action = "rename_relative", desc = "rename base name with changing directory or extension", }, { diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 5f93fc19db7..263e2ba5dbc 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -47,6 +47,7 @@ Api.fs.remove = inject_node(require("nvim-tree.actions.fs.remove-file").fn) Api.fs.trash = inject_node(require("nvim-tree.actions.fs.trash").fn) Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn(false)) Api.fs.rename_sub = inject_node(require("nvim-tree.actions.fs.rename-file").fn(true)) +Api.fs.rename_relative = inject_node(require("nvim-tree.actions.fs.rename-file").fn(false, true)) Api.fs.cut = inject_node(require("nvim-tree.actions.fs.copy-paste").cut) Api.fs.paste = inject_node(require("nvim-tree.actions.fs.copy-paste").paste) Api.fs.clear_clipboard = require("nvim-tree.actions.fs.copy-paste").clear_clipboard From feb22bb3bc77026d8d05c4f021c6534a254cb7a7 Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 3 Dec 2022 16:59:42 +0000 Subject: [PATCH 07/22] =?UTF-8?q?=F0=9F=9A=A8=20correct=20lint=20warnings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/nvim-tree/actions/fs/rename-file.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 8e8367f9edb..fe2e1c3ddce 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -36,9 +36,9 @@ function M.fn(with_sub, relative_rename) local default_path, prepend, append if relative_rename then local filename = node.absolute_path:sub(abs_directory:len() + 1) - local extension_index = filename:find("%.[^%.]*$") or -1 + local extension_index = filename:find"%.[^%.]*$" or -1 if extension_index > 1 then - default_path = filename:sub(0, extension_index -1) + default_path = filename:sub(0, extension_index - 1) append = filename:sub(extension_index) else default_path = filename From 7c70489a73d773f8c5f45aa916b970957fe0d13f Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 4 Dec 2022 12:35:19 +1100 Subject: [PATCH 08/22] rename_relative -> rename_root --- doc/nvim-tree-lua.txt | 6 +++--- lua/nvim-tree/actions/dispatch.lua | 2 +- lua/nvim-tree/actions/init.lua | 4 ++-- lua/nvim-tree/api.lua | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index a0ad65096f2..4a3f82712bf 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -296,7 +296,7 @@ Subsequent calls to setup will replace the previous configuration. debounce_delay = 50, severity = { min = vim.diagnostic.severity.HINT, - max = vim.diagnostic.severity.ERROR + max = vim.diagnostic.severity.ERROR, }, icons = { hint = "", @@ -1328,7 +1328,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings `D` trash trash a file via |trash| option `r` rename rename a file `` full_rename rename a file and omit the filename on input -`e` rename_relative rename base name with changing directory or extension +`e` rename_root rename a file with filename-modifiers ':t:r' without changing extension `x` cut add/remove file/directory to cut clipboard `c` copy add/remove file/directory to copy clipboard `p` paste paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation @@ -1378,7 +1378,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings { key = "D", action = "trash" }, { key = "r", action = "rename" }, { key = "", action = "full_rename" }, - { key = "e", action = "rename_relative" }, + { key = "e", action = "rename_root" }, { key = "x", action = "cut" }, { key = "c", action = "copy" }, { key = "p", action = "paste" }, diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 1e7c6337a8c..547761e45a3 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -25,7 +25,7 @@ local Actions = { trash = require("nvim-tree.actions.fs.trash").fn, remove = require("nvim-tree.actions.fs.remove-file").fn, rename = require("nvim-tree.actions.fs.rename-file").fn(false), - rename_relative = require("nvim-tree.actions.fs.rename-file").fn(false, true), + rename_root = require("nvim-tree.actions.fs.rename-file").fn(false, true), -- Movements in tree close_node = require("nvim-tree.actions.moves.parent").fn(true), diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index f5384e44314..21dada53097 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -123,8 +123,8 @@ local DEFAULT_MAPPINGS = { }, { key = "e", - action = "rename_relative", - desc = "rename base name with changing directory or extension", + action = "rename_root", + desc = "rename a file with filename-modifiers ':t:r' without changing extension" }, { key = "x", diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 263e2ba5dbc..42a0284ad24 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -47,7 +47,7 @@ Api.fs.remove = inject_node(require("nvim-tree.actions.fs.remove-file").fn) Api.fs.trash = inject_node(require("nvim-tree.actions.fs.trash").fn) Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn(false)) Api.fs.rename_sub = inject_node(require("nvim-tree.actions.fs.rename-file").fn(true)) -Api.fs.rename_relative = inject_node(require("nvim-tree.actions.fs.rename-file").fn(false, true)) +Api.fs.rename_root = inject_node(require("nvim-tree.actions.fs.rename-file").fn(false, true)) Api.fs.cut = inject_node(require("nvim-tree.actions.fs.copy-paste").cut) Api.fs.paste = inject_node(require("nvim-tree.actions.fs.copy-paste").paste) Api.fs.clear_clipboard = require("nvim-tree.actions.fs.copy-paste").clear_clipboard From 999f41b49ec8d8496a3fbd7e786be2a7e636dfd0 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 4 Dec 2022 12:35:46 +1100 Subject: [PATCH 09/22] stylua --- lua/nvim-tree/actions/fs/rename-file.lua | 2 +- lua/nvim-tree/actions/init.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index fe2e1c3ddce..d1e93554b85 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -36,7 +36,7 @@ function M.fn(with_sub, relative_rename) local default_path, prepend, append if relative_rename then local filename = node.absolute_path:sub(abs_directory:len() + 1) - local extension_index = filename:find"%.[^%.]*$" or -1 + local extension_index = filename:find "%.[^%.]*$" or -1 if extension_index > 1 then default_path = filename:sub(0, extension_index - 1) append = filename:sub(extension_index) diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index 21dada53097..dd1f0ada88d 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -124,7 +124,7 @@ local DEFAULT_MAPPINGS = { { key = "e", action = "rename_root", - desc = "rename a file with filename-modifiers ':t:r' without changing extension" + desc = "rename a file with filename-modifiers ':t:r' without changing extension", }, { key = "x", From c573ba305461710618a3ef6d462dc66d6a644abc Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sun, 4 Dec 2022 19:50:42 +0000 Subject: [PATCH 10/22] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20use=20fnamemodify=20?= =?UTF-8?q?instead=20of=20custom=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/nvim-tree/actions/fs/rename-file.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index d1e93554b85..be0c71b85ba 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -36,10 +36,10 @@ function M.fn(with_sub, relative_rename) local default_path, prepend, append if relative_rename then local filename = node.absolute_path:sub(abs_directory:len() + 1) - local extension_index = filename:find "%.[^%.]*$" or -1 - if extension_index > 1 then - default_path = filename:sub(0, extension_index - 1) - append = filename:sub(extension_index) + local extension = vim.fn.fnamemodify(node.name, ':e') + if extension:len() > 0 then + default_path = vim.fn.fnamemodify(node.name, ':t:r') + append = "." .. extension else default_path = filename append = "" From b3fd1f23f5fc2dc75be709ca3837a07babbc70af Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Fri, 9 Dec 2022 14:27:52 +0000 Subject: [PATCH 11/22] =?UTF-8?q?=F0=9F=92=A5=20refactor=20renaming=20api?= =?UTF-8?q?=20using=20vim=20filename=20modifiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename API now supports filename modifiers as arguments, although only with limited support of options. The function signature however will allow improvements going forward. The API signature is backward compatible, although the behviour has changed as per the next comment. This change changes the default behaviour of the renames, rename_full is what rename was, rename now just renames the tail (i.e. the filename) --- lua/nvim-tree/actions/dispatch.lua | 2 +- lua/nvim-tree/actions/fs/rename-file.lua | 56 +++++++++++++++--------- lua/nvim-tree/actions/init.lua | 2 +- lua/nvim-tree/api.lua | 3 +- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index 547761e45a3..d34d31c5315 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -25,7 +25,7 @@ local Actions = { trash = require("nvim-tree.actions.fs.trash").fn, remove = require("nvim-tree.actions.fs.remove-file").fn, rename = require("nvim-tree.actions.fs.rename-file").fn(false), - rename_root = require("nvim-tree.actions.fs.rename-file").fn(false, true), + rename_basename = require("nvim-tree.actions.fs.rename-file").fn(":t:r"), -- Movements in tree close_node = require("nvim-tree.actions.moves.parent").fn(true), diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index be0c71b85ba..e05204e516c 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -24,7 +24,32 @@ function M.rename(node, to) events._dispatch_node_renamed(node.absolute_path, to) end -function M.fn(with_sub, relative_rename) +function M.fn(modifier_arg) + local modifier = modifier_arg + -- backwards compatibility, support modifier as boolean + if type(modifier_arg) == "boolean" then + if modifier_arg then + modifier = ":p" + else + modifier = ":t" + end + end + + -- support for only specific modifiers have been implemented + local allowed_modifiers = { + ":p", + ":t", + ":t:r" + } + + local lookup = {} + for _, v in ipairs(allowed_modifiers) do lookup[v] = true end + + if (lookup[modifier] == nil) then + return notify.warn("Modifier " .. modifier .. + " is not in allowed list : "..table.concat(allowed_modifiers, ",")) + end + return function(node) node = lib.get_last_group_node(node) if node.name == ".." then @@ -32,26 +57,17 @@ function M.fn(with_sub, relative_rename) end local namelen = node.name:len() - local abs_directory = node.absolute_path:sub(0, namelen * -1 - 1) - local default_path, prepend, append - if relative_rename then - local filename = node.absolute_path:sub(abs_directory:len() + 1) - local extension = vim.fn.fnamemodify(node.name, ':e') - if extension:len() > 0 then - default_path = vim.fn.fnamemodify(node.name, ':t:r') - append = "." .. extension - else - default_path = filename - append = "" - end - prepend = abs_directory + local directory = node.absolute_path:sub(0, namelen - 1) + local default_path + local prepend = "" + local append = "" + if modifier == ":" then + default_path = directory else - prepend = "" - append = "" - if with_sub then - default_path = abs_directory - else - default_path = node.absolute_path + default_path = vim.fn.fnamemodify(node.name, modifier) + if modifier == ":t:r" then + local extension = vim.fn.fnamemodify(node.name, ':e') + append = extension:len() == 0 and "" or "." ..extension end end diff --git a/lua/nvim-tree/actions/init.lua b/lua/nvim-tree/actions/init.lua index dd1f0ada88d..df20a11658a 100644 --- a/lua/nvim-tree/actions/init.lua +++ b/lua/nvim-tree/actions/init.lua @@ -123,7 +123,7 @@ local DEFAULT_MAPPINGS = { }, { key = "e", - action = "rename_root", + action = "rename_basename", desc = "rename a file with filename-modifiers ':t:r' without changing extension", }, { diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 42a0284ad24..f2c80375b9e 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -45,9 +45,8 @@ Api.tree.toggle_help = require("nvim-tree.actions.tree-modifiers.toggles").help Api.fs.create = inject_node(require("nvim-tree.actions.fs.create-file").fn) Api.fs.remove = inject_node(require("nvim-tree.actions.fs.remove-file").fn) Api.fs.trash = inject_node(require("nvim-tree.actions.fs.trash").fn) -Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn(false)) +Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn) Api.fs.rename_sub = inject_node(require("nvim-tree.actions.fs.rename-file").fn(true)) -Api.fs.rename_root = inject_node(require("nvim-tree.actions.fs.rename-file").fn(false, true)) Api.fs.cut = inject_node(require("nvim-tree.actions.fs.copy-paste").cut) Api.fs.paste = inject_node(require("nvim-tree.actions.fs.copy-paste").paste) Api.fs.clear_clipboard = require("nvim-tree.actions.fs.copy-paste").clear_clipboard From 8ef88c91c44cf61747da54e7d1d7c7f11f7d1cbf Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Fri, 9 Dec 2022 14:51:59 +0000 Subject: [PATCH 12/22] =?UTF-8?q?=F0=9F=90=9B=20make=20api=20rename,=20wit?= =?UTF-8?q?hout=20args,=20functional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/nvim-tree/actions/fs/rename-file.lua | 50 ++++++++++++++---------- lua/nvim-tree/api.lua | 2 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index e05204e516c..bb4115c6f19 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -24,33 +24,41 @@ function M.rename(node, to) events._dispatch_node_renamed(node.absolute_path, to) end -function M.fn(modifier_arg) - local modifier = modifier_arg +function M.fn(initialisation_arg) + local default_modifier = ":t" -- backwards compatibility, support modifier as boolean - if type(modifier_arg) == "boolean" then - if modifier_arg then + if type(initialisation_arg) == "boolean" then + if initialisation_arg then modifier = ":p" - else - modifier = ":t" end + elseif type(initialisation_arg) == "string" then + default_modifier = initialisation_arg end - -- support for only specific modifiers have been implemented - local allowed_modifiers = { - ":p", - ":t", - ":t:r" - } + return function(node, modifier_arg) + local modifier = default_modifier + if modifier_arg ~= nil then + modifier = modifier_arg + end - local lookup = {} - for _, v in ipairs(allowed_modifiers) do lookup[v] = true end + -- support for only specific modifiers have been implemented + local allowed_modifiers = { + ":p", + ":t", + ":t:r", + } - if (lookup[modifier] == nil) then - return notify.warn("Modifier " .. modifier .. - " is not in allowed list : "..table.concat(allowed_modifiers, ",")) - end + local lookup = {} + for _, v in ipairs(allowed_modifiers) do + lookup[v] = true + end + + if lookup[modifier] == nil then + return notify.warn( + "Modifier " .. modifier .. " is not in allowed list : " .. table.concat(allowed_modifiers, ",") + ) + end - return function(node) node = lib.get_last_group_node(node) if node.name == ".." then return @@ -66,8 +74,8 @@ function M.fn(modifier_arg) else default_path = vim.fn.fnamemodify(node.name, modifier) if modifier == ":t:r" then - local extension = vim.fn.fnamemodify(node.name, ':e') - append = extension:len() == 0 and "" or "." ..extension + local extension = vim.fn.fnamemodify(node.name, ":e") + append = extension:len() == 0 and "" or "." .. extension end end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index f2c80375b9e..14685d063e0 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -45,7 +45,7 @@ Api.tree.toggle_help = require("nvim-tree.actions.tree-modifiers.toggles").help Api.fs.create = inject_node(require("nvim-tree.actions.fs.create-file").fn) Api.fs.remove = inject_node(require("nvim-tree.actions.fs.remove-file").fn) Api.fs.trash = inject_node(require("nvim-tree.actions.fs.trash").fn) -Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn) +Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn()) Api.fs.rename_sub = inject_node(require("nvim-tree.actions.fs.rename-file").fn(true)) Api.fs.cut = inject_node(require("nvim-tree.actions.fs.copy-paste").cut) Api.fs.paste = inject_node(require("nvim-tree.actions.fs.copy-paste").paste) From 9bf034ada3a9f8ba09e465d05abed9038b395a5a Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Fri, 9 Dec 2022 15:01:11 +0000 Subject: [PATCH 13/22] =?UTF-8?q?=E2=9C=A8=20allow=20modifier=20argument?= =?UTF-8?q?=20to=20be=20used=20in=20API=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/nvim-tree/actions/fs/rename-file.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index bb4115c6f19..3d147ddceb8 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -35,10 +35,16 @@ function M.fn(initialisation_arg) default_modifier = initialisation_arg end - return function(node, modifier_arg) + return function(modifier_arg) + local node local modifier = default_modifier - if modifier_arg ~= nil then + if type(modifier_arg) == "table" then + node = modifier_arg + elseif type(modifier_arg) == "string" then + node = lib.get_node_at_cursor() modifier = modifier_arg + else + return notify.warn("Type " .. type(modifier_arg) .. " not supported in rename") end -- support for only specific modifiers have been implemented From 5ed452462756f532f5719818f5e693621dcf796c Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Fri, 9 Dec 2022 15:17:46 +0000 Subject: [PATCH 14/22] =?UTF-8?q?=F0=9F=93=9D=20update=20documentation=20w?= =?UTF-8?q?ith=20new=20command=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/nvim-tree-lua.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 4a3f82712bf..8388eff79d5 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1328,7 +1328,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings `D` trash trash a file via |trash| option `r` rename rename a file `` full_rename rename a file and omit the filename on input -`e` rename_root rename a file with filename-modifiers ':t:r' without changing extension +`e` rename_basename rename a file with filename-modifiers ':t:r' without changing extension `x` cut add/remove file/directory to cut clipboard `c` copy add/remove file/directory to copy clipboard `p` paste paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation @@ -1378,7 +1378,7 @@ DEFAULT MAPPINGS *nvim-tree-default-mappings { key = "D", action = "trash" }, { key = "r", action = "rename" }, { key = "", action = "full_rename" }, - { key = "e", action = "rename_root" }, + { key = "e", action = "rename_basename" }, { key = "x", action = "cut" }, { key = "c", action = "copy" }, { key = "p", action = "paste" }, From c097df20963ef55141081c713920a5bb7263dd0b Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 10 Dec 2022 13:15:10 +1100 Subject: [PATCH 15/22] rename-file.fn takes only a modifier as argument --- lua/nvim-tree/actions/dispatch.lua | 6 +++--- lua/nvim-tree/actions/fs/rename-file.lua | 14 +++----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/lua/nvim-tree/actions/dispatch.lua b/lua/nvim-tree/actions/dispatch.lua index d34d31c5315..ecb67eb7d5d 100644 --- a/lua/nvim-tree/actions/dispatch.lua +++ b/lua/nvim-tree/actions/dispatch.lua @@ -20,12 +20,12 @@ local Actions = { copy = require("nvim-tree.actions.fs.copy-paste").copy, create = require("nvim-tree.actions.fs.create-file").fn, cut = require("nvim-tree.actions.fs.copy-paste").cut, - full_rename = require("nvim-tree.actions.fs.rename-file").fn(true), + full_rename = require("nvim-tree.actions.fs.rename-file").fn ":p", paste = require("nvim-tree.actions.fs.copy-paste").paste, trash = require("nvim-tree.actions.fs.trash").fn, remove = require("nvim-tree.actions.fs.remove-file").fn, - rename = require("nvim-tree.actions.fs.rename-file").fn(false), - rename_basename = require("nvim-tree.actions.fs.rename-file").fn(":t:r"), + rename = require("nvim-tree.actions.fs.rename-file").fn ":t", + rename_basename = require("nvim-tree.actions.fs.rename-file").fn ":t:r", -- Movements in tree close_node = require("nvim-tree.actions.moves.parent").fn(true), diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 3d147ddceb8..8dae1633e3b 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -25,16 +25,7 @@ function M.rename(node, to) end function M.fn(initialisation_arg) - local default_modifier = ":t" - -- backwards compatibility, support modifier as boolean - if type(initialisation_arg) == "boolean" then - if initialisation_arg then - modifier = ":p" - end - elseif type(initialisation_arg) == "string" then - default_modifier = initialisation_arg - end - + local default_modifier = initialisation_arg or ":t" return function(modifier_arg) local node local modifier = default_modifier @@ -44,7 +35,8 @@ function M.fn(initialisation_arg) node = lib.get_node_at_cursor() modifier = modifier_arg else - return notify.warn("Type " .. type(modifier_arg) .. " not supported in rename") + node = lib.get_node_at_cursor() + modifier = default_modifier end -- support for only specific modifiers have been implemented From 0f05d7444546d26e1d1ecf44339960dbc980a08b Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 10 Dec 2022 13:33:30 +1100 Subject: [PATCH 16/22] add Api.fs.rename_basename, specify modifiers for rename, rename_sub --- lua/nvim-tree/actions/fs/rename-file.lua | 2 +- lua/nvim-tree/api.lua | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 8dae1633e3b..8c569c79d6b 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -53,7 +53,7 @@ function M.fn(initialisation_arg) if lookup[modifier] == nil then return notify.warn( - "Modifier " .. modifier .. " is not in allowed list : " .. table.concat(allowed_modifiers, ",") + "Modifier " .. vim.inspect(modifier) .. " is not in allowed list : " .. table.concat(allowed_modifiers, ",") ) end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 14685d063e0..3ee8a4ceb04 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -45,8 +45,9 @@ Api.tree.toggle_help = require("nvim-tree.actions.tree-modifiers.toggles").help Api.fs.create = inject_node(require("nvim-tree.actions.fs.create-file").fn) Api.fs.remove = inject_node(require("nvim-tree.actions.fs.remove-file").fn) Api.fs.trash = inject_node(require("nvim-tree.actions.fs.trash").fn) -Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn()) -Api.fs.rename_sub = inject_node(require("nvim-tree.actions.fs.rename-file").fn(true)) +Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn ":t") +Api.fs.rename_sub = inject_node(require("nvim-tree.actions.fs.rename-file").fn ":p") +Api.fs.rename_basename = inject_node(require("nvim-tree.actions.fs.rename-file").fn ":t:r") Api.fs.cut = inject_node(require("nvim-tree.actions.fs.copy-paste").cut) Api.fs.paste = inject_node(require("nvim-tree.actions.fs.copy-paste").paste) Api.fs.clear_clipboard = require("nvim-tree.actions.fs.copy-paste").clear_clipboard From c190007965df69f20b6d5ecd4a300bbe725dec9f Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 10 Dec 2022 14:01:20 +1100 Subject: [PATCH 17/22] add Api.fs.rename_node --- doc/nvim-tree-lua.txt | 2 ++ lua/nvim-tree/actions/fs/rename-file.lua | 19 ++++++++----------- lua/nvim-tree/api.lua | 5 +++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 8388eff79d5..3517584a05d 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1196,8 +1196,10 @@ exists. - create - remove - trash + - rename_node `(node: table, modifier?: string vim.fn.fnamemodify argument)` - rename - rename_sub + - rename_basename - cut - paste - clear_clipboard diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 8c569c79d6b..c7bc2c54b5e 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -24,18 +24,15 @@ function M.rename(node, to) events._dispatch_node_renamed(node.absolute_path, to) end -function M.fn(initialisation_arg) - local default_modifier = initialisation_arg or ":t" - return function(modifier_arg) - local node - local modifier = default_modifier - if type(modifier_arg) == "table" then - node = modifier_arg - elseif type(modifier_arg) == "string" then - node = lib.get_node_at_cursor() - modifier = modifier_arg - else +function M.fn(default_modifier) + default_modifier = default_modifier or ":t" + + return function(node, modifier) + if type(node) ~= "table" then node = lib.get_node_at_cursor() + end + + if type(modifier) ~= "string" then modifier = default_modifier end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 3ee8a4ceb04..0cb209e2d09 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -9,9 +9,9 @@ local Api = { } local function inject_node(f) - return function(node) + return function(node, ...) node = node or require("nvim-tree.lib").get_node_at_cursor() - f(node) + f(node, ...) end end @@ -45,6 +45,7 @@ Api.tree.toggle_help = require("nvim-tree.actions.tree-modifiers.toggles").help Api.fs.create = inject_node(require("nvim-tree.actions.fs.create-file").fn) Api.fs.remove = inject_node(require("nvim-tree.actions.fs.remove-file").fn) Api.fs.trash = inject_node(require("nvim-tree.actions.fs.trash").fn) +Api.fs.rename_node = inject_node(require("nvim-tree.actions.fs.rename-file").fn ":t") Api.fs.rename = inject_node(require("nvim-tree.actions.fs.rename-file").fn ":t") Api.fs.rename_sub = inject_node(require("nvim-tree.actions.fs.rename-file").fn ":p") Api.fs.rename_basename = inject_node(require("nvim-tree.actions.fs.rename-file").fn ":t:r") From fa0154277a5d513b0a5602d382ea1981f64ee30e Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 10 Dec 2022 14:08:03 +1100 Subject: [PATCH 18/22] rename-file tidy allowed modifiers --- lua/nvim-tree/actions/fs/rename-file.lua | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index c7bc2c54b5e..c37277021bc 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -5,6 +5,12 @@ local notify = require "nvim-tree.notify" local M = {} +local ALLOWED_MODIFIERS = { + [":p"] = true, + [":t"] = true, + [":t:r"] = true, +} + local function err_fmt(from, to, reason) return string.format("Cannot rename %s -> %s: %s", from, to, reason) end @@ -37,20 +43,9 @@ function M.fn(default_modifier) end -- support for only specific modifiers have been implemented - local allowed_modifiers = { - ":p", - ":t", - ":t:r", - } - - local lookup = {} - for _, v in ipairs(allowed_modifiers) do - lookup[v] = true - end - - if lookup[modifier] == nil then + if not ALLOWED_MODIFIERS[modifier] then return notify.warn( - "Modifier " .. vim.inspect(modifier) .. " is not in allowed list : " .. table.concat(allowed_modifiers, ",") + "Modifier " .. vim.inspect(modifier) .. " is not in allowed list : " .. table.concat(ALLOWED_MODIFIERS, ",") ) end From ff670c8ba0f58c6fa1c72c346071f0a36a0a6653 Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 10 Dec 2022 17:06:18 +0000 Subject: [PATCH 19/22] =?UTF-8?q?=F0=9F=90=9B=20fix=20bugs=20after=20last?= =?UTF-8?q?=20refactoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rename ":t" and ":t:r" was moving file to root of project and not maintaining sub-directory --- lua/nvim-tree/actions/fs/rename-file.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index c37277021bc..7c8bc1e9fd8 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -55,22 +55,23 @@ function M.fn(default_modifier) end local namelen = node.name:len() - local directory = node.absolute_path:sub(0, namelen - 1) + local directory = node.absolute_path:sub(0, namelen * -1 - 1) local default_path local prepend = "" local append = "" - if modifier == ":" then - default_path = directory - else - default_path = vim.fn.fnamemodify(node.name, modifier) - if modifier == ":t:r" then - local extension = vim.fn.fnamemodify(node.name, ":e") - append = extension:len() == 0 and "" or "." .. extension - end + default_path = vim.fn.fnamemodify(node.name, modifier) + if modifier:sub(0,2) == ":t" then + prepend = directory + end + if modifier == ":t:r" then + local extension = vim.fn.fnamemodify(node.name, ":e") + append = extension:len() == 0 and "" or "." .. extension end local input_opts = { prompt = "Rename to ", default = default_path, completion = "file" } + print(prepend .. "|" .. default_path .. "|" .. append) + vim.ui.input(input_opts, function(new_file_path) utils.clear_prompt() if not new_file_path then From 98bbb0904b2b37e2f5199ea06ab0f04a123f1f06 Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 10 Dec 2022 17:12:36 +0000 Subject: [PATCH 20/22] =?UTF-8?q?=F0=9F=90=9B=20correct=20absolute=20renam?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit which was loosing sub-directory on rename --- lua/nvim-tree/actions/fs/rename-file.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 7c8bc1e9fd8..dc04c16b3da 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -59,7 +59,9 @@ function M.fn(default_modifier) local default_path local prepend = "" local append = "" - default_path = vim.fn.fnamemodify(node.name, modifier) + print(modifier) + print(node.name) + default_path = vim.fn.fnamemodify(node.absolute_path, modifier) if modifier:sub(0,2) == ":t" then prepend = directory end From 7dc6eda08494992c57923f1aeab634fc665b33c6 Mon Sep 17 00:00:00 2001 From: Ian Homer Date: Sat, 10 Dec 2022 17:27:02 +0000 Subject: [PATCH 21/22] =?UTF-8?q?=F0=9F=94=A5=20remove=20debug=20print=20s?= =?UTF-8?q?tatements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/nvim-tree/actions/fs/rename-file.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index dc04c16b3da..a97992d7ed0 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -59,8 +59,6 @@ function M.fn(default_modifier) local default_path local prepend = "" local append = "" - print(modifier) - print(node.name) default_path = vim.fn.fnamemodify(node.absolute_path, modifier) if modifier:sub(0,2) == ":t" then prepend = directory @@ -72,8 +70,6 @@ function M.fn(default_modifier) local input_opts = { prompt = "Rename to ", default = default_path, completion = "file" } - print(prepend .. "|" .. default_path .. "|" .. append) - vim.ui.input(input_opts, function(new_file_path) utils.clear_prompt() if not new_file_path then From 3354ab35d3677ddf83c18801749a8825324e2973 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 11 Dec 2022 12:16:35 +1100 Subject: [PATCH 22/22] stylua --- lua/nvim-tree/actions/fs/rename-file.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index a97992d7ed0..a494ab09de8 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -60,7 +60,7 @@ function M.fn(default_modifier) local prepend = "" local append = "" default_path = vim.fn.fnamemodify(node.absolute_path, modifier) - if modifier:sub(0,2) == ":t" then + if modifier:sub(0, 2) == ":t" then prepend = directory end if modifier == ":t:r" then