fix(#2523): live filter overlay width calculation (#2524)

* fix: live filter overlay width calculation

* refactor: simplify calculate_width return if not wininfo

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
geril2207 2023-11-13 01:49:14 +03:00 committed by GitHub
parent 874ae6e944
commit 80cfeadf17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,8 +105,17 @@ local function configure_buffer_overlay()
vim.api.nvim_buf_set_keymap(overlay_bufnr, "i", "<CR>", "<cmd>stopinsert<CR>", {}) vim.api.nvim_buf_set_keymap(overlay_bufnr, "i", "<CR>", "<cmd>stopinsert<CR>", {})
end end
local function calculate_overlay_win_width()
local wininfo = vim.fn.getwininfo(view.get_winnr())[1]
if wininfo then
return wininfo.width - wininfo.textoff - #M.prefix
end
return 20
end
local function create_overlay() local function create_overlay()
local min_width = 20
if view.View.float.enable then if view.View.float.enable then
-- don't close nvim-tree float when focus is changed to filter window -- don't close nvim-tree float when focus is changed to filter window
vim.api.nvim_clear_autocmds { vim.api.nvim_clear_autocmds {
@ -114,8 +123,6 @@ local function create_overlay()
pattern = "NvimTree_*", pattern = "NvimTree_*",
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
} }
min_width = min_width - 2
end end
configure_buffer_overlay() configure_buffer_overlay()
@ -123,7 +130,7 @@ local function create_overlay()
col = 1, col = 1,
row = 0, row = 0,
relative = "cursor", relative = "cursor",
width = math.max(min_width, vim.api.nvim_win_get_width(view.get_winnr()) - #M.prefix - 2), width = calculate_overlay_win_width(),
height = 1, height = 1,
border = "none", border = "none",
style = "minimal", style = "minimal",