A floating vim.ui.input buffer that auto-resizes to fit its contents.
0

Configure Feed

Select the types of activity you want to include in your feed.

refactor resize

r0nsha (Jun 27, 2025, 5:09 PM +0300) eef73f7a f7c24e5d

+17 -22
+17 -22
lua/lib/input.lua
··· 83 83 or vim.api.nvim_get_option_value("relativenumber", { win = self.winnr }) 84 84 end 85 85 86 - function Input:resize_empty() 87 - local height = 1 88 - vim.api.nvim_win_set_height(self.winnr, height) 86 + ---@param width integer 87 + ---@param height integer 88 + function Input:set_size(width, height) 89 + local h = utils.clamp(height, self.config.height.min, self.config.height.max) 90 + vim.api.nvim_win_set_height(self.winnr, h) 89 91 90 - local width = 91 - utils.clamp(self.config.padding, self.config.width.min, self.config.width.max) 92 - width = self:set_numbers(height) 93 - and width + utils.get_linenr_width(self.winnr, self.bufnr) 94 - or width 95 - vim.api.nvim_win_set_width(self.winnr, width) 92 + local w = utils.clamp( 93 + width + self.config.padding, 94 + self.config.width.min, 95 + self.config.width.max 96 + ) 97 + 98 + local has_numbers = self:set_numbers(h) 99 + w = has_numbers and w + utils.get_linenr_width(self.winnr, self.bufnr) or w 100 + w = w + 2 -- HACK: add padding to avoid glitches 101 + vim.api.nvim_win_set_width(self.winnr, w) 96 102 end 97 103 98 104 function Input:resize() ··· 100 106 local line = table.concat(text, "") 101 107 102 108 if line == "" then 103 - self:resize_empty() 109 + self:set_size(0, 1) 104 110 return 105 111 end 106 112 107 113 local lines = utils.split_wrapped_lines(line, self.config.width.max) 108 114 109 - local height = utils.clamp(#lines, self.config.height.min, self.config.height.max) 110 - vim.api.nvim_win_set_height(self.winnr, height) 111 - 112 115 local lens = vim.tbl_map(function(l) 113 116 return vim.fn.strdisplaywidth(l) 114 117 end, lines) 115 - local width = utils.clamp( 116 - math.max(unpack(lens)) + self.config.padding, 117 - self.config.width.min, 118 - self.config.width.max 119 - ) 120 118 121 - width = self:set_numbers(height) 122 - and width + utils.get_linenr_width(self.winnr, self.bufnr) 123 - or width 124 - vim.api.nvim_win_set_width(self.winnr, width) 119 + self:set_size(math.max(unpack(lens)), #lines) 125 120 end 126 121 127 122 function Input:autocmds()