From bb8d54e1943c143e9cb65534c4f7e2cba3903f73 Mon Sep 17 00:00:00 2001 From: Fabian David Schmidt Date: Wed, 15 Nov 2023 16:45:31 +0100 Subject: [PATCH 1/3] fix(actions): correctly rename open (dir) buffers --- .../_extensions/file_browser/actions.lua | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lua/telescope/_extensions/file_browser/actions.lua b/lua/telescope/_extensions/file_browser/actions.lua index 9b1d3165..07b667f3 100755 --- a/lua/telescope/_extensions/file_browser/actions.lua +++ b/lua/telescope/_extensions/file_browser/actions.lua @@ -342,17 +342,25 @@ fb_actions.move = function(prompt_bufnr) local skipped = {} for idx, selection in ipairs(selections) do - local filename = selection.filename:sub(#selection:parent().filename + 2) - local new_path = Path:new { target_dir, filename } + -- use vim.fs rather than plenary to fetch basename, more battle-tested + local old_path_absolute = selection:absolute() + local basename = vim.fs.basename(old_path_absolute) + local new_path = Path:new { target_dir, basename } if new_path:exists() then - table.insert(skipped, filename) + table.insert(skipped, basename) else + local new_path_absolute = new_path:absolute() selection:rename { - new_name = new_path.filename, + new_name = new_path_absolute, } - table.insert(moved, filename) + if not selection:is_dir() then + fb_utils.rename_buf(old_path_absolute, new_path_absolute) + else + fb_utils.rename_dir_buf(old_path_absolute, new_path_absolute) + end + table.insert(moved, basename) if idx == 1 and #selections == 1 then - fb_utils.selection_callback(current_picker, new_path:absolute()) + fb_utils.selection_callback(current_picker, new_path_absolute) end end end From 689ad6d333e2e86bd8c1c374868c5ff67e895b2e Mon Sep 17 00:00:00 2001 From: Fabian David Schmidt Date: Wed, 15 Nov 2023 17:03:29 +0100 Subject: [PATCH 2/3] docs(actions): document order sensitivity of moving --- lua/telescope/_extensions/file_browser/actions.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/telescope/_extensions/file_browser/actions.lua b/lua/telescope/_extensions/file_browser/actions.lua index 07b667f3..175337d4 100755 --- a/lua/telescope/_extensions/file_browser/actions.lua +++ b/lua/telescope/_extensions/file_browser/actions.lua @@ -325,7 +325,11 @@ fb_actions.rename = function(prompt_bufnr) end --- Move multi-selected files or folders to current directory in |telescope-file-browser.picker.file_browser|.
---- Note: Performs a blocking synchronized file-system operation. +--- - Notes: +--- - Performs a blocking synchronized file-system operation. +--- - Moving multi-selections is sensitive to order of selection, +--- which potentially unpacks files from parent(s) dirs +--- if files are selected first. ---@param prompt_bufnr number: The prompt bufnr fb_actions.move = function(prompt_bufnr) local current_picker = action_state.get_current_picker(prompt_bufnr) From af9197efb620209bf32747aaa525bb3eae407194 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Wed, 15 Nov 2023 16:06:22 +0000 Subject: [PATCH 3/3] [docgen] Update doc/telescope-file-browser.txt skip-checks: true --- doc/telescope-file-browser.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/telescope-file-browser.txt b/doc/telescope-file-browser.txt index 3d1fdf5c..fb6d1700 100644 --- a/doc/telescope-file-browser.txt +++ b/doc/telescope-file-browser.txt @@ -253,7 +253,12 @@ fb_actions.rename({prompt_bufnr}) *telescope-file-browser.actions.rename()* fb_actions.move({prompt_bufnr}) *telescope-file-browser.actions.move()* Move multi-selected files or folders to current directory in |telescope-file-browser.picker.file_browser|. - Note: Performs a blocking synchronized file-system operation. + + - Notes: + - Performs a blocking synchronized file-system operation. + - Moving multi-selections is sensitive to order of selection, which + potentially unpacks files from parent(s) dirs if files are selected + first. Parameters: ~