Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Jan 9, 2025
1 parent 1091a3d commit 20f0313
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/dired/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,25 @@ Browser.refresh = function(state, path)
return a.name < b.name
end)

local cfg = api.nvim_win_get_config(state.win)
local maxwidth = 0
-- Update buffer
local formatted_entries = vim.tbl_map(function(entry)
return UI.Entry.render(entry)
local line = UI.Entry.render(entry)
maxwidth = math.max(maxwidth, #line)
return line
end, collected_entries)

vim.bo[state.buf].modifiable = true
api.nvim_buf_set_lines(state.buf, 2, -1, false, formatted_entries)
vim.bo[state.buf].modifiable = false
api.nvim_win_set_cursor(state.win, { 3, 55 })

-- update window width for better look
cfg.width = math.min(cfg.width, maxwidth + 5)
cfg.col = math.floor((vim.o.columns - cfg.width) / 2)
api.nvim_win_set_config(state.win, cfg)

UI.Highlights.set_header_highlights(state.buf, ns_id)
for i, entry in ipairs(collected_entries) do
UI.Highlights.set_entry_highlights(state.buf, ns_id, i + 1, entry)
Expand Down

0 comments on commit 20f0313

Please sign in to comment.