Snacks Explorer Width and Resize #2139
Unanswered
mestrellar28
asked this question in
Q&A
Replies: 1 comment
-
opts = {
picker = {
sources = {
explorer = {
-- Variant 1
-- layout = function()
-- local init_width = 50
-- local sidebar = vim.deepcopy(require('snacks.picker.config.layouts').sidebar)
-- sidebar.layout.width = init_width
-- sidebar.layout.min_width = init_width
-- return sidebar
-- end,
-- Variant 2 (preferred)
-- https://github.com/folke/snacks.nvim/blob/bc0630e43be5699bb94dadc302c0d21615421d93/lua/snacks/picker/config/layouts.lua#L22-L42
layout = {
preview = 'main',
layout = {
backdrop = false,
width = 40, -- Pfff.. 40. I have 60!
min_width = 40,
height = 0,
position = 'left',
border = 'none',
box = 'vertical',
{
win = 'input',
height = 1,
border = 'rounded',
title = '{title} {live} {flags}',
title_pos = 'center',
},
{ win = 'list', border = 'none' },
{ win = 'preview', title = '{preview}', height = 0.4, border = 'top' },
},
},
actions = {
-- Variant 1 (preferred)
inc_width = function(picker)
local win = picker.layout.root.win
if win then
local width = vim.api.nvim_win_get_config(win).width + 5
vim.api.nvim_win_set_config(win, { width = width })
picker.resolved_layout.layout.width = width
end
end,
-- Variant 2 (poor perf)
dec_width = function(picker)
local layout = vim.deepcopy(picker.resolved_layout)
local width = layout.layout.width - 5
---@cast width number
layout.layout.width = width
layout.layout.min_width = width
picker:set_layout(layout)
end,
},
win = {
list = {
keys = {
['<Right>'] = 'inc_width',
['<Left>'] = 'dec_width', |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, how can i set the initial width to Snacks Explorer and how can I resize the width with a keymap? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions