diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index cb1054e..09dbd7a 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1385,9 +1385,11 @@ function Sidebar:create_input() width = win_width - 2, -- Subtract the width of the input box borders }, }, { + disable_cursor_position_patch = true, prompt = Config.windows.prompt.prefix, - default_value = "", + default_value = " ", on_submit = function(user_input) + user_input = Utils.trim_spaces(user_input) if user_input == "" then self:create_input() return diff --git a/lua/avante/utils/init.lua b/lua/avante/utils/init.lua index d5506cc..754cd7e 100644 --- a/lua/avante/utils/init.lua +++ b/lua/avante/utils/init.lua @@ -30,11 +30,14 @@ function M.trim(str, opts) if not opts then return str end + local res = str if opts.suffix then - return str:sub(-1) == opts.suffix and str:sub(1, -2) or str - elseif opts.prefix then - return str:sub(1, 1) == opts.prefix and str:sub(2) or str + res = str:sub(#str - #opts.suffix + 1) == opts.suffix and str:sub(1, #str - #opts.suffix) or str end + if opts.prefix then + res = str:sub(1, #opts.prefix) == opts.prefix and str:sub(#opts.prefix + 1) or str + end + return res end function M.in_visual_mode() @@ -316,4 +319,8 @@ function M.is_sidebar_buffer(bufnr) return v == true end +function M.trim_spaces(s) + return s:match("^%s*(.-)%s*$") +end + return M