minimal extui fuzzy finder for neovim

refactor(view): move `win_config` to method

+23 -23
+23 -23
lua/artio/view.lua
··· 32 32 33 33 local prompt_hl_id = vim.api.nvim_get_hl_id_by_name("ArtioPrompt") 34 34 35 - --- Set the 'cmdheight' and cmdline window height. Reposition message windows. 36 - --- 37 - ---@param win integer Cmdline window in the current tabpage. 38 - ---@param hide boolean Whether to hide or show the window. 39 - ---@param height integer (Text)height of the cmdline window. 40 - local function win_config(win, hide, height) 41 - if ui2.cmdheight == 0 and vim.api.nvim_win_get_config(win).hide ~= hide then 42 - vim.api.nvim_win_set_config(win, { hide = hide, height = not hide and height or nil }) 43 - elseif vim.api.nvim_win_get_height(win) ~= height then 44 - vim.api.nvim_win_set_height(win, height) 45 - end 46 - if vim.o.cmdheight ~= height then 47 - -- Avoid moving the cursor with 'splitkeep' = "screen", and altering the user 48 - -- configured value with noautocmd. 49 - vim._with({ noautocmd = true, o = { splitkeep = "screen" } }, function() 50 - vim.o.cmdheight = height 51 - end) 52 - ui2.msg.set_pos() 53 - end 54 - end 55 - 56 35 ---@class artio.View 57 36 ---@field picker artio.Picker 58 37 ---@field closed boolean ··· 169 148 self:hlselect() 170 149 end 171 150 151 + --- Set the 'cmdheight' and cmdline window height. Reposition message windows. 152 + --- 153 + ---@param win integer Cmdline window in the current tabpage. 154 + ---@param hide boolean Whether to hide or show the window. 155 + ---@param height integer (Text)height of the cmdline window. 156 + function View:win_config(win, hide, height) 157 + if ui2.cmdheight == 0 and vim.api.nvim_win_get_config(win).hide ~= hide then 158 + vim.api.nvim_win_set_config(win, { hide = hide, height = not hide and height or nil }) 159 + elseif vim.api.nvim_win_get_height(win) ~= height then 160 + vim.api.nvim_win_set_height(win, height) 161 + end 162 + if vim.o.cmdheight ~= height then 163 + -- Avoid moving the cursor with 'splitkeep' = "screen", and altering the user 164 + -- configured value with noautocmd. 165 + vim._with({ noautocmd = true, o = { splitkeep = "screen" } }, function() 166 + vim.o.cmdheight = height 167 + end) 168 + ui2.msg.set_pos() 169 + end 170 + end 171 + 172 172 ---@param predicted? integer The predicted height of the cmdline window 173 173 function View:updatewinheight(predicted) 174 174 local height = math.max(1, predicted or vim.api.nvim_win_text_height(ui2.wins.cmd, {}).all) 175 175 height = math.min(height, self.win.height) 176 - win_config(ui2.wins.cmd, false, height) 176 + self:win_config(ui2.wins.cmd, false, height) 177 177 end 178 178 179 179 function View:saveview() ··· 391 391 clear(cmdline.prompt) 392 392 393 393 cmdline.prompt, cmdline.level = false, 0 394 - win_config(ui2.wins.cmd, true, ui2.cmdheight) 394 + self:win_config(ui2.wins.cmd, true, ui2.cmdheight) 395 395 end 396 396 397 397 function View:trigger_show()