Skip to content

Commit

Permalink
Toggle chat
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhiya committed Jun 2, 2024
1 parent f516ab5 commit 2fc5ee0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/fittencode/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ M.api = {
show_chat = function()
return ActionsEngine.show_chat()
end,
toggle_chat = function()
return ActionsEngine.toggle_chat()
end,
}

return M
2 changes: 2 additions & 0 deletions lua/fittencode/bindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ function M.setup_commands()
stop_eval = API.stop_eval,
-- Arguments: Nop
show_chat = API.show_chat,
-- Arguments: Nop
toggle_chat = API.toggle_chat,
}
Base.command('Fitten', function(line)
---@type string[]
Expand Down
8 changes: 8 additions & 0 deletions lua/fittencode/engines/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -690,4 +690,12 @@ function ActionsEngine.show_chat()
chat:show()
end

function ActionsEngine.toggle_chat()
if chat:is_visible() then
chat:close()
else
chat:show()
end
end

return ActionsEngine
5 changes: 5 additions & 0 deletions lua/fittencode/views/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local Log = require('fittencode.log')
---@field create function
---@field last_cursor? table
---@field callbacks table
---@field is_visible function
local M = {}

function M:new(callbacks)
Expand Down Expand Up @@ -158,4 +159,8 @@ function M:commit(lines)
return _commit(self.window, self.buffer, lines)
end

function M:is_visible()
return self.window and api.nvim_win_is_valid(self.window)
end

return M

0 comments on commit 2fc5ee0

Please sign in to comment.