feat(ui): add support for multi-line messages in confirm dialog
1. Split message into multiple lines using vim.split() 2. Apply indent to each line of the message using vim.tbl_map() 3. Improve code readability by using vim.iter() and chained methods 4. Simplify button line generation with string.rep() Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz>
This commit is contained in:
@@ -42,13 +42,19 @@ function M.confirm(message, callback)
|
||||
local yes_style = (focus_index == 1) and BUTTON_FOCUS or BUTTON_NORMAL
|
||||
local no_style = (focus_index == 2) and BUTTON_FOCUS or BUTTON_NORMAL
|
||||
|
||||
vim.api.nvim_buf_set_lines(popup.bufnr, 0, -1, false, {
|
||||
"",
|
||||
" " .. message,
|
||||
"",
|
||||
" " .. " Yes No ",
|
||||
"",
|
||||
})
|
||||
local button_line = string.rep(" ", 23) .. " Yes No "
|
||||
local replacement = vim
|
||||
.iter({
|
||||
"",
|
||||
vim.tbl_map(function(line) return " " .. line end, vim.split(message, "\n")),
|
||||
"",
|
||||
button_line,
|
||||
"",
|
||||
})
|
||||
:flatten()
|
||||
:totable()
|
||||
|
||||
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])
|
||||
|
||||
Reference in New Issue
Block a user