Skip to content

Commit 6efe464

Browse files
committed
fix: skip BufEnter logic if buf already prepared (issue: #139)
1 parent 676b03a commit 6efe464

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lua/gp/init.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ M.display_chat_agent = function(buf, file_name)
494494
})
495495
end
496496

497+
M._prepared_bufs = {}
497498
M.prep_chat = function(buf, file_name)
498499
if M.not_chat(buf, file_name) then
499500
return
@@ -503,6 +504,13 @@ M.prep_chat = function(buf, file_name)
503504
return
504505
end
505506

507+
M.refresh_state({ last_chat = file_name })
508+
if M._prepared_bufs[buf] then
509+
M.logger.debug("buffer already prepared: " .. buf)
510+
return
511+
end
512+
M._prepared_bufs[buf] = true
513+
506514
M.prep_md(buf)
507515

508516
if M.config.chat_prompt_buf_type then
@@ -559,8 +567,6 @@ M.prep_chat = function(buf, file_name)
559567
vim.fn.matchadd("Conceal", [[^- role: .\{64,64\}\zs.*\ze]], 10, -1, { conceal = "" })
560568
vim.fn.matchadd("Conceal", [[^- role: .[^\\]*\zs\\.*\ze]], 10, -1, { conceal = "" })
561569
end
562-
563-
M.refresh_state({ last_chat = file_name })
564570
end
565571

566572
M.buf_handler = function()
@@ -1604,6 +1610,11 @@ M.prep_context = function(buf, file_name)
16041610
if buf ~= vim.api.nvim_get_current_buf() then
16051611
return
16061612
end
1613+
if M._prepared_bufs[buf] then
1614+
M.logger.debug("buffer already prepared: " .. buf)
1615+
return
1616+
end
1617+
M._prepared_bufs[buf] = true
16071618

16081619
M.prep_md(buf)
16091620
end

0 commit comments

Comments
 (0)