Skip to content

Commit

Permalink
fix: skip BufEnter logic if buf already prepared (issue: #139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robitx committed Aug 4, 2024
1 parent 63098a5 commit 2c3d818
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ M.display_chat_agent = function(buf, file_name)
})
end

M._prepared_bufs = {}
M.prep_chat = function(buf, file_name)
if M.not_chat(buf, file_name) then
return
Expand All @@ -503,6 +504,13 @@ M.prep_chat = function(buf, file_name)
return
end

M.refresh_state({ last_chat = file_name })
if M._prepared_bufs[buf] then
M.logger.debug("buffer already prepared: " .. buf)
return
end
M._prepared_bufs[buf] = true

M.prep_md(buf)

if M.config.chat_prompt_buf_type then
Expand Down Expand Up @@ -559,8 +567,6 @@ M.prep_chat = function(buf, file_name)
vim.fn.matchadd("Conceal", [[^- role: .\{64,64\}\zs.*\ze]], 10, -1, { conceal = "" })
vim.fn.matchadd("Conceal", [[^- role: .[^\\]*\zs\\.*\ze]], 10, -1, { conceal = "" })
end

M.refresh_state({ last_chat = file_name })
end

M.buf_handler = function()
Expand Down Expand Up @@ -1604,6 +1610,11 @@ M.prep_context = function(buf, file_name)
if buf ~= vim.api.nvim_get_current_buf() then
return
end
if M._prepared_bufs[buf] then
M.logger.debug("buffer already prepared: " .. buf)
return
end
M._prepared_bufs[buf] = true

M.prep_md(buf)
end
Expand Down

0 comments on commit 2c3d818

Please sign in to comment.