From 6b11ac7fd50ee2270b4062aaa82b0466c0ffc8f0 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Aug 2024 13:29:28 +0800 Subject: [PATCH] perf(selection): reduce the number of times indentation is calculated (#412) --- lua/avante/selection.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/avante/selection.lua b/lua/avante/selection.lua index 638277d..d9648af 100644 --- a/lua/avante/selection.lua +++ b/lua/avante/selection.lua @@ -377,13 +377,14 @@ function Selection:create_editing_input() local original_first_line_indentation = Utils.get_indentation(code_lines[self.selection.range.start.line]) + local need_prepend_indentation = false + api.nvim_exec_autocmds("User", { pattern = EDITING_INPUT_START_SPINNER_PATTERN }) ---@type AvanteChunkParser local on_chunk = function(chunk) full_response = full_response .. chunk local response_lines = vim.split(full_response, "\n") - local need_prepend_indentation = false - if #response_lines > 0 then + if #response_lines == 1 then local first_line = response_lines[1] local first_line_indentation = Utils.get_indentation(first_line) need_prepend_indentation = first_line_indentation ~= original_first_line_indentation