@@ -7,6 +7,22 @@ local events = require "nvim-tree.events"
77
88local M = {}
99
10+ function M .rename (node , to )
11+ if utils .file_exists (to ) then
12+ utils .warn " Cannot rename: file already exists"
13+ return
14+ end
15+
16+ local success = uv .fs_rename (node .absolute_path , to )
17+ if not success then
18+ return a .nvim_err_writeln (" Could not rename " .. node .absolute_path .. " to " .. to )
19+ end
20+ utils .clear_prompt ()
21+ a .nvim_out_write (node .absolute_path .. " ➜ " .. to .. " \n " )
22+ utils .rename_loaded_buffers (node .absolute_path , to )
23+ events ._dispatch_node_renamed (node .absolute_path , to )
24+ end
25+
1026function M .fn (with_sub )
1127 return function (node )
1228 node = lib .get_last_group_node (node )
@@ -24,19 +40,7 @@ function M.fn(with_sub)
2440 return
2541 end
2642
27- if utils .file_exists (new_file_path ) then
28- utils .warn " Cannot rename: file already exists"
29- return
30- end
31-
32- local success = uv .fs_rename (node .absolute_path , new_file_path )
33- if not success then
34- return a .nvim_err_writeln (" Could not rename " .. node .absolute_path .. " to " .. new_file_path )
35- end
36- utils .clear_prompt ()
37- a .nvim_out_write (node .absolute_path .. " ➜ " .. new_file_path .. " \n " )
38- utils .rename_loaded_buffers (node .absolute_path , new_file_path )
39- events ._dispatch_node_renamed (abs_path , new_file_path )
43+ M .rename (node , new_file_path )
4044 if M .enable_reload then
4145 require (" nvim-tree.actions.reloaders.reloaders" ).reload_explorer ()
4246 end
0 commit comments