fix: correct button rendering for multi-line messages in confirmation dialog
This commit fixes an issue where buttons in the confirmation dialog would not render properly when displaying multi-line messages. Changes: - Add dynamic positioning for buttons based on message length - Calculate button row position based on the number of lines in the message - Update focus_button function to accept custom row parameter - Ensure highlights are applied at correct positions for varied message lengths Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz>
This commit is contained in:
@@ -30,11 +30,12 @@ function M.confirm(message, callback)
|
||||
},
|
||||
})
|
||||
|
||||
local function focus_button()
|
||||
local function focus_button(row)
|
||||
row = row or 4
|
||||
if focus_index == 1 then
|
||||
vim.api.nvim_win_set_cursor(popup.winid, { 4, yes_button_pos[1] })
|
||||
vim.api.nvim_win_set_cursor(popup.winid, { row, yes_button_pos[1] })
|
||||
else
|
||||
vim.api.nvim_win_set_cursor(popup.winid, { 4, no_button_pos[1] })
|
||||
vim.api.nvim_win_set_cursor(popup.winid, { row, no_button_pos[1] })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,6 +44,7 @@ function M.confirm(message, callback)
|
||||
local no_style = (focus_index == 2) and BUTTON_FOCUS or BUTTON_NORMAL
|
||||
|
||||
local button_line = string.rep(" ", 23) .. " Yes No "
|
||||
local button_line_num = 2 + #vim.split(message, "\n")
|
||||
local replacement = vim
|
||||
.iter({
|
||||
"",
|
||||
@@ -56,9 +58,9 @@ function M.confirm(message, callback)
|
||||
|
||||
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, replacement)
|
||||
|
||||
vim.api.nvim_buf_add_highlight(popup.bufnr, 0, yes_style, 3, yes_button_pos[1], yes_button_pos[2])
|
||||
vim.api.nvim_buf_add_highlight(popup.bufnr, 0, no_style, 3, no_button_pos[1], no_button_pos[2])
|
||||
focus_button()
|
||||
vim.api.nvim_buf_add_highlight(popup.bufnr, 0, yes_style, button_line_num, yes_button_pos[1], yes_button_pos[2])
|
||||
vim.api.nvim_buf_add_highlight(popup.bufnr, 0, no_style, button_line_num, no_button_pos[1], no_button_pos[2])
|
||||
focus_button(button_line_num + 1)
|
||||
end
|
||||
|
||||
local function select_button()
|
||||
|
||||
Reference in New Issue
Block a user