From 0d309f388b9a4db8ad1b0926ba18f07cb68d0209 Mon Sep 17 00:00:00 2001 From: r0nsha Date: Fri, 27 Jun 2025 16:48:22 +0300 Subject: [PATCH] fix: cursor overlaps linenr when `numbers` is enabled --- lua/lib/input.lua | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lua/lib/input.lua b/lua/lib/input.lua index 268bb40..dd420c6 100644 --- a/lua/lib/input.lua +++ b/lua/lib/input.lua @@ -74,9 +74,9 @@ function Input:close(result) self.on_confirm(result) end ----@param width integer ---@param height integer -function Input:set_numbers(width, height) +---@return boolean +function Input:set_numbers(height) if self.config.opts.numbers == "always" or (self.config.opts.numbers == "multiline" and height > 1) @@ -85,12 +85,18 @@ function Input:set_numbers(width, height) utils.set_option_if_globally_enabled("relativenumber", self.winnr) end - if - vim.api.nvim_get_option_value("number", { win = self.winnr }) + return vim.api.nvim_get_option_value("number", { win = self.winnr }) or vim.api.nvim_get_option_value("relativenumber", { win = self.winnr }) - then - vim.api.nvim_win_set_width(self.winnr, width + utils.get_linenr_width()) - end +end + +function Input:resize_empty() + local height = 1 + vim.api.nvim_win_set_height(self.winnr, height) + + local width = + utils.clamp(self.config.padding, self.config.width.min, self.config.width.max) + width = self:set_numbers(height) and width + utils.get_linenr_width() or width + vim.api.nvim_win_set_width(self.winnr, width) end function Input:resize() @@ -98,20 +104,15 @@ function Input:resize() local line = table.concat(text, "") if line == "" then - local width = utils.clamp( - self.config.padding, - self.config.width.min, - self.config.width.max - ) - local height = 1 - vim.api.nvim_win_set_width(self.winnr, width) - vim.api.nvim_win_set_height(self.winnr, height) - self:set_numbers(width, height) + self:resize_empty() return end local lines = utils.split_wrapped_lines(line, self.config.width.max) + local height = utils.clamp(#lines, self.config.height.min, self.config.height.max) + vim.api.nvim_win_set_height(self.winnr, height) + local lens = vim.tbl_map(function(l) return vim.fn.strdisplaywidth(l) end, lines) @@ -120,12 +121,9 @@ function Input:resize() self.config.width.min, self.config.width.max ) - vim.api.nvim_win_set_width(self.winnr, width) - local height = utils.clamp(#lines, self.config.height.min, self.config.height.max) - vim.api.nvim_win_set_height(self.winnr, height) - - self:set_numbers(width, height) + width = self:set_numbers(height) and width + utils.get_linenr_width() or width + vim.api.nvim_win_set_width(self.winnr, width) end function Input:autocmds() -- 2.54.0