-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(picker): new file explorer Snacks.picker.explorer()
#793
Conversation
…er, will close it instead (toggle)
…o focus (if anything) when showing the picker
… can change the resolved options
…e pickers were open)
…ayout with backdrop opens
…for the next render. Target clears when reached, or when finders finishes.
…or indent guides to file formatter
…dit actions. Fixes #791
@dpetka2001 this part might cause issues: close = function(p, _)
vim.cmd("noh")
p:close()
end, You're probably unaware but this will override the |
However, even with that I still can't reproduce it. |
Just tried it with a minimal repro and still can't reproduce. |
Are you using a winbar plugin by any chance? |
No winbar. Just tried a fresh LazyVim installation and it works there. Will dig in further to find out what's causing this, so please disregard for the time being until I manage to come up with new info or not. |
A question: Would it be possible that the Explorer Sidebar stays open after I select an item? I personally would like that. But I also can live without it. I have found the This ---@field auto_close? boolean automatically close the picker when focusing another window (defaults to true) |
Just added |
Thats awesome. Thank you 🙏 |
I found the culprit for being dropped into |
That's odd indeed! No idea what that plugin does or why it would cause issues. I added the extra Let me know if you do find anhything! |
Hey @folke, Noticed an error in the explorer. Steps to reproduce:
Screen.Recording.2025-01-30.at.22.07.45.mov |
This works now, but now the chosen file doesnt open when picked from the list. It does open when searched for in the input. Screen.Recording.2025-01-30.at.22.03.09.mp4I also should find a way to disable the blink completion when inside that explorer input.. 🤔 Edit - Found a way: |
Indeed, would be nice to have an easy way to disable the blink completion. Had the same feeling |
blink is disabled by default in prompt buffers and the snacks picker input is a prompt buffer, so if that's not working for you it means you probably changed your blink config. |
I did it like this. working fine for me now: https://github.com/nikbrunner/nbr.nvim/blob/244ec9317429a8efc253c2603324abc5a606a501/lua/nbr/specs/blink.lua?plain=1#L9-L11 |
@JensPauwels fixed that issue with closing the last window. |
I haven't been able to find out what's causing this. Will probably try taking another look tomorrow. For the time being I ended up defining my own close action for the explorer like this explorer = {
win = {
input = {
keys = {
["<Esc>"] = { "my_close", mode = "i" },
},
},
},
actions = {
my_close = function(picker)
vim.cmd("stopinsert")
picker.input.win:close()
end,
},
}, Is this better than doing |
@nikbrunner like I said blink excludes prompt buffers by default, so you can just not confiugure that setting. |
@dpetka2001 does it also work if you change it to just |
Is there a way to disable opening a previous file in the tree explorer? (using ) Screen.Recording.2025-01-30.at.22.28.06.mov |
Yes, it does. I just did it like this because of what you mentioned in your previous comment about overwriting the default close = function(p, _)
vim.cmd("noh")
p:close()
end,
And also in the other custom picker |
As someone who's also done something similar (in fact, sole user of tree-branch in telescope-file-browser.nvim for 2 years 😅) and is in the process of switching to Snacks I thought I might leave a few suggestions for additional actions/slight behavior changes (just opinionated ideas, please feel free to ignore).
I tried something locally like this confirm = function(picker)
local state = M.get_state(picker)
local item = picker:current()
if not item then
return
elseif item.dir then
state:toggle(item)
if vim.api.nvim_get_current_win() == picker.input.win.win then
picker.input:set("", "")
vim.defer_fn(function()
for idx, item_ in ipairs(picker.list.items) do
if item_.file == item.file then
picker.list:move(idx)
break
end
end
end, 100)
end
else
picker:action("jump")
end
end, though couldn't quite get it to work (it doesn't jump to correct node for some reason). My telescope expertise doesn't translate 1:1 to the Snacks picker yet I'm afraid ;) but maybe that idea is welcome as a default.
The way I did this in my file-browser tree branch above is that a user
That said, in my file browser the user practically speaking only interacted with the prompt as telescope didn't support interacting with the results (list) window. So it's quite a different UX.
Edit: here's an implementation for anyone curious local function open_subdirs(picker)
local state = require("snacks.picker.source.explorer").get_state(picker)
local parent = picker:current().parent
local file = parent.file
for _, item_ in ipairs(picker.list.items) do
if item_.parent and item_.parent.file == file then
state:expand(item_.file)
end
end
state:update {
on_done = function()
for item_, idx in picker:iter() do
if item_.file == file then
picker.list:view(idx)
break
end
end
end,
}
end
local function collapse_subdirs(picker)
local state = require("snacks.picker.source.explorer").get_state(picker)
local item = picker:current()
if not item then
return
end
if item.dir then
state.expanded[item.file] = nil
end
state.expanded[item.parent.file] = nil
local file = item.parent.file
state:update {
on_done = function()
for item_, idx in picker:iter() do
if item_.file == file then
picker.list:view(idx)
break
end
end
end,
}
end
|
@fdschmidt93 you can select multiple files with Good idea on that open of dirs from search. Will add |
@fdschmidt93 added in 605f745 |
@dpetka2001 added that explicit close function, so your work-around should no longer be needed. |
🤖 I have created a release *beep* *boop* --- ## [2.17.0](v2.16.0...v2.17.0) (2025-01-30) ### Features * **picker.actions:** allow selecting the visual selection with `<Tab>` ([96c76c6](96c76c6)) * **picker.explorer:** focus dir on confirm from search ([605f745](605f745)) ### Bug Fixes * **git:** basic support for git work trees ([d76d9aa](d76d9aa)) * **picker.preview:** properly refresh the preview after layout changes. Fixes [#802](#802) ([47993f9](47993f9)) * **picker:** add proper close ([15a9411](15a9411)) * **picker:** make jumping work again... ([f40f338](f40f338)) * **picker:** show help for input / list window with `?`. ([87dab7e](87dab7e)) * **win:** properly handle closing the last window. Fixes [#793](#793) ([18de5bb](18de5bb)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@folke can you expose an optional configuration for just showing the basename of the directory thats currently visiable on cwd. This takes away way too much space, just the basename of directory should be enough. and maybe an explorer_help method to get some additional information about the cwd?. If possible inserting a |
@UtsavBalar1231 that's because you disabled the tree. |
Description
File explorer picker.
Testing
Screenshots