@@ -41,6 +41,11 @@ local transform_mod = require("telescope.actions.mt").transform_mod
4141local Path = require " plenary.path"
4242local popup = require " plenary.popup"
4343
44+ -- custom input cb so finder works with built-in input
45+ local stem_prompt = function (prompt )
46+ return { prompt = prompt :find (Path .path .sep ) and table.remove (Path :new (prompt ):_split ()) or prompt }
47+ end
48+
4449local fb_actions = setmetatable ({}, {
4550 __index = function (_ , k )
4651 error (" Key does not exist for 'fb_actions': " .. tostring (k ))
@@ -101,7 +106,13 @@ fb_actions.create = function(prompt_bufnr)
101106 local finder = current_picker .finder
102107
103108 local default = get_target_dir (finder ) .. os_sep
104- vim .ui .input ({ prompt = " Insert the file name: " , default = default , completion = " file" }, function (input )
109+ -- vim.ui.input({ prompt = "Insert the file name: ", default = default }, function(file)
110+ fb_utils .input ({
111+ prompt = " Insert the file name: " ,
112+ default = default ,
113+ prompt_bufnr = prompt_bufnr ,
114+ on_input_filter_cb = stem_prompt ,
115+ }, function (input )
105116 vim .cmd [[ redraw ]] -- redraw to clear out vim.ui.prompt to avoid hit-enter prompt
106117 local file = create (input , finder )
107118 if file then
@@ -232,51 +243,58 @@ fb_actions.rename = function(prompt_bufnr)
232243 fb_utils .notify (" action.rename" , { msg = " Please select a valid file or folder!" , level = " WARN" , quiet = quiet })
233244 return
234245 end
235- vim .ui .input ({ prompt = " Insert a new name: " , default = old_path :absolute (), completion = " file" }, function (file )
236- vim .cmd [[ redraw ]] -- redraw to clear out vim.ui.prompt to avoid hit-enter prompt
237- if file == " " or file == nil then
238- fb_utils .notify (" action.rename" , { msg = " Renaming aborted!" , level = " WARN" , quiet = quiet })
239- return
240- end
241- local new_path = Path :new (file )
242-
243- if old_path .filename == new_path .filename then
244- fb_utils .notify (" action.rename" , {
245- msg = string.format (
246- " Name of selection unchanged! Skipping." ,
247- new_path .filename :sub (# new_path :parent ().filename + 2 )
248- ),
249- level = " WARN" ,
250- quiet = quiet ,
251- })
252- return
253- end
254- if new_path :exists () then
255- fb_utils .notify (" action.rename" , {
256- msg = string.format (" %s already exists! Skipping." , new_path .filename :sub (# new_path :parent ().filename + 2 )),
257- level = " WARN" ,
258- quiet = quiet ,
259- })
260- return
261- end
246+ fb_utils .input (
247+ {
248+ prompt = " Rename: " .. table.remove (entry .Path :_split ()),
249+ prompt_bufnr = prompt_bufnr ,
250+ on_input_filter_cb = stem_prompt ,
251+ },
252+ function (file )
253+ vim .cmd [[ redraw ]] -- redraw to clear out vim.ui.prompt to avoid hit-enter prompt
254+ if file == " " or file == nil then
255+ fb_utils .notify (" action.rename" , { msg = " Renaming aborted!" , level = " WARN" , quiet = quiet })
256+ return
257+ end
258+ local new_path = Path :new (file )
259+
260+ if old_path .filename == new_path .filename then
261+ fb_utils .notify (" action.rename" , {
262+ msg = string.format (
263+ " Name of selection unchanged! Skipping." ,
264+ new_path .filename :sub (# new_path :parent ().filename + 2 )
265+ ),
266+ level = " WARN" ,
267+ quiet = quiet ,
268+ })
269+ return
270+ end
271+ if new_path :exists () then
272+ fb_utils .notify (" action.rename" , {
273+ msg = string.format (" %s already exists! Skipping." , new_path .filename :sub (# new_path :parent ().filename + 2 )),
274+ level = " WARN" ,
275+ quiet = quiet ,
276+ })
277+ return
278+ end
262279
263- -- rename changes old_name in place
264- local old_name = old_path :absolute ()
280+ -- rename changes old_name in place
281+ local old_name = old_path :absolute ()
265282
266- old_path :rename { new_name = new_path .filename }
267- if not new_path :is_dir () then
268- fb_utils .rename_buf (old_name , new_path :absolute ())
269- else
270- fb_utils .rename_dir_buf (old_name , new_path :absolute ())
271- end
283+ old_path :rename { new_name = new_path .filename }
284+ if not new_path :is_dir () then
285+ fb_utils .rename_buf (old_name , new_path :absolute ())
286+ else
287+ fb_utils .rename_dir_buf (old_name , new_path :absolute ())
288+ end
272289
273- -- persist multi selections unambiguously by only removing renamed entry
274- if current_picker :is_multi_selected (entry ) then
275- current_picker ._multi :drop (entry )
290+ -- persist multi selections unambiguously by only removing renamed entry
291+ if current_picker :is_multi_selected (entry ) then
292+ current_picker ._multi :drop (entry )
293+ end
294+ fb_utils .selection_callback (current_picker , new_path :absolute ())
295+ current_picker :refresh (current_picker .finder )
276296 end
277- fb_utils .selection_callback (current_picker , new_path :absolute ())
278- current_picker :refresh (current_picker .finder )
279- end )
297+ )
280298 end
281299end
282300
@@ -383,9 +401,9 @@ fb_actions.copy = function(prompt_bufnr)
383401 end
384402 if exists then
385403 exists = false
386- vim . ui .input ({
404+ fb_utils .input ({
387405 prompt = string.format (
388- " Please enter a new name, <CR> to overwrite (merge), or <ESC> to skip file (folder):\n " ,
406+ " Please enter a new name, <CR> to overwrite (merge), or <ESC> to skip file (folder):" ,
389407 name
390408 ),
391409 default = destination :absolute (),
@@ -457,29 +475,33 @@ fb_actions.remove = function(prompt_bufnr)
457475 local message = " Selections to be deleted: " .. table.concat (files , " , " )
458476 fb_utils .notify (" actions.remove" , { msg = message , level = " INFO" , quiet = quiet })
459477 -- TODO fix default vim.ui.input and nvim-notify 'selections to be deleted' message
460- vim .ui .input ({ prompt = " Remove selections [y/N]: " }, function (input )
461- vim .cmd [[ redraw ]] -- redraw to clear out vim.ui.prompt to avoid hit-enter prompt
462- if input and input :lower () == " y" then
463- for _ , p in ipairs (selections ) do
464- local is_dir = p :is_dir ()
465- p :rm { recursive = is_dir }
466- -- clean up opened buffers
467- if not is_dir then
468- fb_utils .delete_buf (p :absolute ())
469- else
470- fb_utils .delete_dir_buf (p :absolute ())
478+ -- vim.ui.input({ prompt = "Remove selections [y/N]: " }, function(input)
479+ fb_utils .input (
480+ { prompt = " Remove selections [y/N]: " , prompt_bufnr = prompt_bufnr , on_input_filter_cb = stem_prompt },
481+ function (input )
482+ vim .cmd [[ redraw ]] -- redraw to clear out vim.ui.prompt to avoid hit-enter prompt
483+ if input and input :lower () == " y" then
484+ for _ , p in ipairs (selections ) do
485+ local is_dir = p :is_dir ()
486+ p :rm { recursive = is_dir }
487+ -- clean up opened buffers
488+ if not is_dir then
489+ fb_utils .delete_buf (p :absolute ())
490+ else
491+ fb_utils .delete_dir_buf (p :absolute ())
492+ end
493+ table.insert (removed , p .filename :sub (# p :parent ().filename + 2 ))
471494 end
472- table.insert (removed , p .filename :sub (# p :parent ().filename + 2 ))
495+ fb_utils .notify (
496+ " actions.remove" ,
497+ { msg = " Removed: " .. table.concat (removed , " , " ), level = " INFO" , quiet = quiet }
498+ )
499+ current_picker :refresh (current_picker .finder )
500+ else
501+ fb_utils .notify (" actions.remove" , { msg = " Removing selections aborted!" , level = " INFO" , quiet = quiet })
473502 end
474- fb_utils .notify (
475- " actions.remove" ,
476- { msg = " Removed: " .. table.concat (removed , " , " ), level = " INFO" , quiet = quiet }
477- )
478- current_picker :refresh (current_picker .finder )
479- else
480- fb_utils .notify (" actions.remove" , { msg = " Removing selections aborted!" , level = " INFO" , quiet = quiet })
481503 end
482- end )
504+ )
483505end
484506
485507--- Toggle hidden files or folders for |telescope-file-browser.picker.file_browser|.
0 commit comments