Skip to content

Commit

Permalink
Autocreate prompt content if entry is nil (#317)
Browse files Browse the repository at this point in the history
* When entry in prompt doesn't yield any results, <cr> will create it on
the filesystem.

* Update config.lua

* Update picker.lua
  • Loading branch information
CKolkey authored Sep 23, 2023
1 parent c21bdae commit 6e51d0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lua/telescope/_extensions/file_browser/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,22 @@ _TelescopeFileBrowserConfig = {
},
},
attach_mappings = function()
action_set.select:replace_if(function()
-- test whether selected entry is directory
local entry_is_dir = function()
local entry = action_state.get_selected_entry()
return entry and entry.Path:is_dir()
end, fb_actions.open_dir)
end

local entry_is_nil = function(prompt_bufnr)
local prompt = action_state.get_current_picker(prompt_bufnr):_get_prompt()
local entry = action_state.get_selected_entry()

return entry == nil and #prompt > 0
end

action_set.select:replace_map {
[entry_is_dir] = fb_actions.open_dir,
[entry_is_nil] = fb_actions.create_from_prompt,
}

return true
end,
Expand Down
3 changes: 2 additions & 1 deletion lua/telescope/_extensions/file_browser/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ local fb_picker = {}
--- List, create, delete, rename, or move files and folders of your cwd.<br>
--- Notes
--- - Default keymaps in insert/normal mode:
--- - `<cr>` : Opens the currently selected file, or navigates to the currently selected directory
--- - `<cr>` : Opens the currently selected file/directory, or creates whatever is in the prompt
--- - `<s-cr>` : Create path in prompt
--- - `/`, `\` : (OS Path separator) When typing filepath, the path separator will open a directory like `<cr>`.
--- - `<A-c>/c`: Create file/folder at current `path` (trailing path separator creates folder)
--- - `<A-r>/r`: Rename multi-selected files/folders
Expand Down

0 comments on commit 6e51d0c

Please sign in to comment.