Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unmodifiable error #225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lua/chatgpt/flows/chat/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ function Chat:addAnswerPartial(text, state)
end_line = end_line,
})
self.selectedIndex = self.selectedIndex + 1
vim.api.nvim_buf_set_lines(self.chat_window.bufnr, -1, -1, false, { "", "" })
if vim.api.nvim_buf_get_option(self.chat_window.bufnr, "modifiable") then
vim.api.nvim_buf_set_lines(self.chat_window.bufnr, -1, -1, false, { "", "" })
end
Signs.set_for_lines(self.chat_window.bufnr, start_line, end_line, "chat")
end

Expand All @@ -260,12 +262,16 @@ function Chat:addAnswerPartial(text, state)

for i, line in ipairs(lines) do
local currentLine = vim.api.nvim_buf_get_lines(buffer, -2, -1, false)[1]
vim.api.nvim_buf_set_lines(buffer, -2, -1, false, { currentLine .. line })
if vim.api.nvim_buf_get_option(buffer, "modifiable") then
vim.api.nvim_buf_set_lines(buffer, -2, -1, false, { currentLine .. line })
end

local last_line_num = vim.api.nvim_buf_line_count(buffer)
Signs.set_for_lines(self.chat_window.bufnr, start_line, last_line_num - 1, "chat")
if i == length and i > 1 then
vim.api.nvim_buf_set_lines(buffer, -1, -1, false, { "" })
if vim.api.nvim_buf_get_option(buffer, "modifiable") then
vim.api.nvim_buf_set_lines(buffer, -1, -1, false, { "" })
end
end
if self:is_buf_visiable() then
vim.api.nvim_win_set_cursor(win, { last_line_num, 0 })
Expand Down Expand Up @@ -699,7 +705,9 @@ function Chat:open()
end),
on_submit = function(value)
-- clear input
vim.api.nvim_buf_set_lines(self.chat_input.bufnr, 0, -1, false, { "" })
if vim.api.nvim_buf_get_option(self.chat_input.bufnr, "modifiable") then
vim.api.nvim_buf_set_lines(self.chat_input.bufnr, 0, -1, false, { "" })
end

if self:isBusy() then
vim.notify("I'm busy, please wait a moment...", vim.log.levels.WARN)
Expand Down Expand Up @@ -846,7 +854,9 @@ function Chat:open()
local lines = vim.api.nvim_buf_get_lines(self.chat_input.bufnr, 0, -1, false)
local text = table.concat(lines, "\n")
if #text > 0 then
vim.api.nvim_buf_set_lines(self.chat_input.bufnr, 0, -1, false, { "" })
if vim.api.nvim_buf_get_option(self.chat_input.bufnr, "modifiable") then
vim.api.nvim_buf_set_lines(self.chat_input.bufnr, 0, -1, false, { "" })
end
self:add(self.role == ROLE_USER and QUESTION or ANSWER, text)
if self.role ~= ROLE_USER then
self.role = ROLE_USER
Expand Down