Skip to content

Commit cd923db

Browse files
committed
feat: some fixes
1 parent b23c72b commit cd923db

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

lua/telescope/_extensions/file_browser/actions.lua

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -317,44 +317,42 @@ fb_actions.copy = function(prompt_bufnr)
317317
local copy_selections
318318
copy_selections = function()
319319
-- scoping
320-
local selection, name, absolute_path, destination, within_dir
321-
320+
local selection, name, destination, exists
321+
-- TODO disallow copying parent folder into sub-folder
322322
while index <= #selections do
323323
selection = selections[index]
324-
absolute_path = selection:absolute()
325-
name = selection:absolute() ~= target_dir and selection.filename:sub(#selection:parent().filename + 2) or nil
324+
name = table.remove(selection:_split())
326325
destination = Path:new {
327326
target_dir,
328327
name,
329328
}
330329
-- copying file or folder within original directory
331-
if destination:absolute() == absolute_path then
332-
within_dir = true -- trigger vim.ui.input outside loop
330+
if destination:exists() then
331+
exists = true -- trigger vim.ui.input outside loop to avoid interleaving
333332
break
334333
else
335-
selection:copy {
336-
destination = destination,
337-
recursive = true,
338-
parents = true,
339-
}
340-
table.insert(copied, name)
334+
if selection:is_dir() and selection:absolute() == destination:parent():absolute() then
335+
local message = string.format("Copying folder into itself not (yet) supported", name)
336+
fb_utils.notify("actions.copy", { msg = message, level = "INFO", quiet = finder.quiet })
337+
else
338+
selection:copy {
339+
destination = destination,
340+
recursive = true,
341+
parents = true,
342+
}
343+
table.insert(copied, name)
344+
end
341345
index = index + 1
342346
end
343347
end
344-
if within_dir then
345-
within_dir = false
348+
if exists then
349+
exists = false
346350
vim.ui.input({
347-
prompt = string.format("Copying selection within original directory, please provide a new name:", name),
348-
default = absolute_path,
351+
prompt = string.format("Target exists, enter new name or <CR/ESC> to overwrite (join) file (dirs)/pass entry:\n", name),
352+
default = destination:absolute(),
349353
}, function(input)
350354
vim.cmd [[ redraw ]] -- redraw to clear out vim.ui.prompt to avoid hit-enter prompt
351-
if input == nil then
352-
local message = string.format("Copying %s aborted!", name)
353-
fb_utils.notify("actions.copy", { msg = message, level = "INFO", quiet = finder.quiet })
354-
elseif input == absolute_path then
355-
local message = string.format("Source and target are identical for copying %s! Skipping.", name)
356-
fb_utils.notify("actions.copy", { msg = message, level = "INFO", quiet = finder.quiet })
357-
else
355+
if input ~= nil then
358356
selection:copy {
359357
destination = input,
360358
recursive = true,
@@ -370,8 +368,8 @@ fb_actions.copy = function(prompt_bufnr)
370368
local message = "These entries were copied: " .. table.concat(copied, ", ")
371369
fb_utils.notify("actions.copy", { msg = message, level = "INFO", quiet = finder.quiet })
372370
end
373-
current_picker:refresh(current_picker.finder, { reset_prompt = true })
374371
end
372+
current_picker:refresh(current_picker.finder, { reset_prompt = true })
375373
end
376374
copy_selections()
377375
end
@@ -469,7 +467,7 @@ fb_actions.goto_parent_dir = function(prompt_bufnr, bypass)
469467
if not bypass then
470468
if vim.loop.cwd() == finder.path then
471469
fb_utils.notify(
472-
"action.rename",
470+
"action.goto_parent_dir",
473471
{ msg = "You cannot bypass the current working directory!", level = "WARN", quiet = finder.quiet }
474472
)
475473
return
@@ -504,7 +502,7 @@ fb_actions.change_cwd = function(prompt_bufnr)
504502

505503
fb_utils.redraw_border_title(current_picker)
506504
current_picker:refresh(finder, { reset_prompt = true, multi = current_picker._multi })
507-
fb_utils.notify("action.rename", { msg = "Set the current working directory!", level = "INFO", quiet = finder.quiet })
505+
fb_utils.notify("action.change_cwd", { msg = "Set the current working directory!", level = "INFO", quiet = finder.quiet })
508506
end
509507

510508
--- Goto home directory in |telescope-file-browser.picker.file_browser|.

lua/telescope/_extensions/file_browser/make_entry.lua

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local utils = require "telescope.utils"
22
local entry_display = require "telescope.pickers.entry_display"
3+
local action_state = require "telescope.actions.state"
34
local state = require "telescope.state"
45
local Path = require "plenary.path"
56
local os_sep = Path.path.sep
@@ -45,6 +46,25 @@ local DATE = {
4546

4647
local stat_enum = { size = SIZE, date = DATE }
4748

49+
local get_fb_prompt = function()
50+
local prompt_buf = vim.tbl_filter(function(b)
51+
return vim.bo[b].filetype == "TelescopePrompt"
52+
end, vim.api.nvim_list_bufs())
53+
-- vim.ui.{input, select} might be telescope pickers
54+
if #prompt_buf > 1 then
55+
for _, buf in ipairs(prompt_buf) do
56+
local current_picker = action_state.get_current_picker(prompt_buf)
57+
if current_picker.finder._browse_files then
58+
prompt_buf = buf
59+
break
60+
end
61+
end
62+
else
63+
prompt_buf = prompt_buf[1]
64+
end
65+
return prompt_buf
66+
end
67+
4868
-- General:
4969
-- telescope-file-browser unlike telescope
5070
-- caches "made" entries to retain multi-selections
@@ -56,9 +76,8 @@ local stat_enum = { size = SIZE, date = DATE }
5676
-- - Path: cache plenary.Path object of entry
5777
-- - stat: lazily cached vim.loop.fs_stat of entry
5878
local make_entry = function(opts)
59-
local prompt_buf = vim.api.nvim_get_current_buf()
79+
local prompt_buf = get_fb_prompt()
6080
local status = state.get_status(prompt_buf)
61-
6281
-- Compute total file width of results buffer:
6382
-- The results buffer typically splits like this with this notation {item, width}
6483
-- {devicon, 1} { name, variable }, { stat, stat_width, typically right_justify }

0 commit comments

Comments
 (0)