Skip to content

Commit 3510217

Browse files
committed
fix: check for underflow during backticks trimming (issue: #152)
1 parent 58f5c85 commit 3510217

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lua/gp/init.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ M.Prompt = function(params, target, agent, template, prompt, whisper, callback)
17631763
local fl = qt.first_line
17641764
local ll = qt.last_line
17651765
-- remove empty lines from the start and end of the response
1766-
while true do
1766+
while fl < ll do
17671767
-- get content of first_line and last_line
17681768
flc = vim.api.nvim_buf_get_lines(buf, fl, fl + 1, false)[1]
17691769
llc = vim.api.nvim_buf_get_lines(buf, ll, ll + 1, false)[1]
@@ -1780,11 +1780,6 @@ M.Prompt = function(params, target, agent, template, prompt, whisper, callback)
17801780
break
17811781
end
17821782

1783-
-- break loop lines are equal
1784-
if fl >= ll then
1785-
break
1786-
end
1787-
17881783
if not flm then
17891784
M.helpers.undojoin(buf)
17901785
vim.api.nvim_buf_set_lines(buf, fl, fl + 1, false, {})
@@ -1796,7 +1791,7 @@ M.Prompt = function(params, target, agent, template, prompt, whisper, callback)
17961791
end
17971792

17981793
-- if fl and ll starts with triple backticks, remove these lines
1799-
if flc and llc and flc:match("^%s*```") and llc:match("^%s*```") then
1794+
if fl < ll and flc and llc and flc:match("^%s*```") and llc:match("^%s*```") then
18001795
-- remove first line with undojoin
18011796
M.helpers.undojoin(buf)
18021797
vim.api.nvim_buf_set_lines(buf, fl, fl + 1, false, {})

0 commit comments

Comments
 (0)