From 3dd5bed48fa315df9a2ba1d064dc5182452e8e1c Mon Sep 17 00:00:00 2001 From: Hanchin Hsieh Date: Mon, 17 Mar 2025 16:18:27 +0800 Subject: [PATCH] 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 --- lua/avante/ui.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lua/avante/ui.lua b/lua/avante/ui.lua index 0334c0a..a97be21 100644 --- a/lua/avante/ui.lua +++ b/lua/avante/ui.lua @@ -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])