Closed endoze closed 2 weeks ago
Telescope one is already there. :Telescope themes
there's arrow keys &
@siduck If you export the functions that allow moving the selection up and down in the new theme switcher, anyone could then re-use those functions as part of keybinds. I'm not asking for specific keybinds to be added, just enable the ability to use the up/down functions outside of the ui plugin. Something like this would get added in my own configuration:
map("i", "<C-j>", require('nvchad.themes').move_down, { desc = "<Down>" })
map("I", "<C-k>", require('nvchad.themes').move_up, { desc = "<Up>"})
alright, i'll move the helper functions into nvchad.themes.api
module and then let you know when done
the thing is how would you pass the buffer :thinking:
At first glance, I wouldn't think you'd need to pass the buffer as part of the keybind. If it's considered the current buffer, you can always internally use [nvim_get_current_buff
](https://neovim.io/doc/user/api.html#nvim_get_current_buf()) or just pass 0 as the buffer id.
But I looked into how telescope does their selection keybinds and I have the following table as part of the setup function for telescope.
mappings = {
i = {
["<C-j>"] = function(...)
require("telescope.actions").move_selection_next(...)
end,
["<C-k>"] = function(...)
require("telescope.actions").move_selection_previous(...)
end,
},
n = {
["d"] = function(...)
require("telescope.actions").delete_buffer(...)
end,
},
},
I'm not entirely sure what gets passed into these functions but I'm forwarding all arguments as is into the move_selection_next
, move_selection_previous
, and delete_buffer
functions. If this doesn't help enough, I can try my hand at implementing it as well.
I just figured at first glance you'd be more intimately familiar with the new theme switcher code and might make short work of exposing these for keybind usage 😊.
i'll try it tomorrow, something like this :
require("nvchad.themes").open({
mappings = function(buf)
-- do here
end
})
Can you by chance share what you have so far? I'd be happy to pick up where you've left off and send back to you for review once I'm done.
@siduck I've created a pull request with what I think might work for adding custom keybinds for the new theme switcher on #359. I opted to use Chadrc for configuration values instead of relying on passing things into the open
function for the themes.
map("n", "<leader>th", function()
require("nvchad.themes").open {
mappings = function(buf)
vim.keymap.set("i", "<C-k>", require("nvchad.themes.api").move_up, { buffer = buf })
vim.keymap.set("i", "<C-j>", require("nvchad.themes.api").move_down, { buffer = buf })
end,
}
end, { desc = "telescope nvchad themes" })
Since the new theme switcher replaced the Telescope based one, I think it should support customizing keybinds. Previously with telescope, all pre-configured keybinds for selection/movement/etc worked with the NvChad themes picker. But it currently seems like the new theme picker doesn't expose any way to customize keybinds for it.