Skip to content

Commit

Permalink
Step 5
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed May 24, 2024
1 parent 225bb7e commit f50f509
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lua/fittencode/engines/actions/content.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function M:commit(opts)
end

table.insert(self.buffer_content, lines)
return self.chat:commit(lines), lines
return self.chat:commit(lines)
end

function M:on_start(opts)
Expand Down
22 changes: 12 additions & 10 deletions lua/fittencode/suggestions_preprocessing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ local function condense_nl(opts)
table.remove(suggestions, non_empty + 3)
end

local row, col = Base.get_cursor(window)
local prev_line = nil
local cur_line = api.nvim_buf_get_lines(buffer, row, row + 1, false)[1]
if row > 1 then
prev_line = api.nvim_buf_get_lines(buffer, row - 1, row, false)[1]
end

local nls = {}
local remove_all = false
local keep_first = true
Expand All @@ -60,9 +53,18 @@ local function condense_nl(opts)
remove_all = true
end

if #cur_line == 0 then
if not prev_line or #prev_line == 0 then
remove_all = true
if window and buffer and api.nvim_buf_is_valid(buffer) and api.nvim_win_is_valid(window) then
local row, col = Base.get_cursor(window)
local prev_line = nil
local cur_line = api.nvim_buf_get_lines(buffer, row, row + 1, false)[1]
if row > 1 then
prev_line = api.nvim_buf_get_lines(buffer, row - 1, row, false)[1]
end

if #cur_line == 0 then
if not prev_line or #prev_line == 0 then
remove_all = true
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/fittencode/views/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end

local function _commit(window, buffer, lines)
local cursor = {}
if api.nvim_buf_is_valid(buffer) and api.nvim_win_is_valid(window) then
if window and buffer and api.nvim_buf_is_valid(buffer) and api.nvim_win_is_valid(window) then
api.nvim_set_option_value('modifiable', true, { buf = buffer })
api.nvim_set_option_value('readonly', false, { buf = buffer })
cursor = Lines.set_text({
Expand Down

0 comments on commit f50f509

Please sign in to comment.