fix(input): move hints to bottom right (#533)
Uses vim.fn.winline() to determine correct hint buffer position
This commit is contained in:
parent
19a7d84d1e
commit
8c021f3691
@ -1374,6 +1374,13 @@ function Sidebar:create_input()
|
||||
end
|
||||
end
|
||||
|
||||
local function get_float_window_row()
|
||||
local win_height = vim.api.nvim_win_get_height(self.input.winid)
|
||||
local winline = Utils.winline(self.input.winid)
|
||||
if winline >= win_height - 1 then return 0 end
|
||||
return winline
|
||||
end
|
||||
|
||||
-- Create a floating window as a hint
|
||||
local function show_hint()
|
||||
close_hint() -- Close the existing hint window
|
||||
@ -1386,7 +1393,6 @@ function Sidebar:create_input()
|
||||
|
||||
-- Get the current window size
|
||||
local win_width = api.nvim_win_get_width(self.input.winid)
|
||||
local buf_height = api.nvim_buf_line_count(self.input.bufnr)
|
||||
local width = #hint_text
|
||||
|
||||
-- Set the floating window options
|
||||
@ -1395,7 +1401,7 @@ function Sidebar:create_input()
|
||||
win = self.input.winid,
|
||||
width = width,
|
||||
height = 1,
|
||||
row = buf_height,
|
||||
row = get_float_window_row(),
|
||||
col = math.max(win_width - width, 0), -- Display in the bottom right corner
|
||||
style = "minimal",
|
||||
border = "none",
|
||||
@ -1409,7 +1415,7 @@ function Sidebar:create_input()
|
||||
api.nvim_win_set_hl_ns(hint_window, Highlights.hint_ns)
|
||||
end
|
||||
|
||||
api.nvim_create_autocmd({ "TextChanged", "TextChangedI" }, {
|
||||
api.nvim_create_autocmd({ "TextChanged", "TextChangedI", "VimResized" }, {
|
||||
group = self.augroup,
|
||||
buffer = self.input.bufnr,
|
||||
callback = function()
|
||||
|
@ -514,4 +514,12 @@ function M.debounce(func, delay)
|
||||
end
|
||||
end
|
||||
|
||||
function M.winline(winid)
|
||||
local current_win = vim.api.nvim_get_current_win()
|
||||
vim.api.nvim_set_current_win(winid)
|
||||
local line = vim.fn.winline()
|
||||
vim.api.nvim_set_current_win(current_win)
|
||||
return line
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
x
Reference in New Issue
Block a user