From 80cfeadf179d5cba76f0f502c71dbcff1b515cd8 Mon Sep 17 00:00:00 2001 From: geril2207 <62308020+geril2207@users.noreply.github.com> Date: Mon, 13 Nov 2023 01:49:14 +0300 Subject: [PATCH] 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 --- lua/nvim-tree/live-filter.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree/live-filter.lua b/lua/nvim-tree/live-filter.lua index 5d52c53d..6e510cba 100644 --- a/lua/nvim-tree/live-filter.lua +++ b/lua/nvim-tree/live-filter.lua @@ -105,8 +105,17 @@ local function configure_buffer_overlay() vim.api.nvim_buf_set_keymap(overlay_bufnr, "i", "", "stopinsert", {}) 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 min_width = 20 if view.View.float.enable then -- don't close nvim-tree float when focus is changed to filter window vim.api.nvim_clear_autocmds { @@ -114,8 +123,6 @@ local function create_overlay() pattern = "NvimTree_*", group = vim.api.nvim_create_augroup("NvimTree", { clear = false }), } - - min_width = min_width - 2 end configure_buffer_overlay() @@ -123,7 +130,7 @@ local function create_overlay() col = 1, row = 0, 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, border = "none", style = "minimal",