Skip to content

Commit

Permalink
fix(responsehandler): window handling
Browse files Browse the repository at this point in the history
  • Loading branch information
frankroeder committed Sep 3, 2024
1 parent ead51c9 commit f2cbfc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lua/parrot/response_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ ResponseHandler.__index = ResponseHandler
function ResponseHandler:new(queries, buffer, window, line, first_undojoin, prefix, cursor)
local self = setmetatable({}, ResponseHandler)
self.buffer = buffer or vim.api.nvim_get_current_buf()
self.window = window
self.window = window or vim.api.nvim_get_current_win()
self.prefix = prefix or ""
self.cursor = cursor or false
self.first_line = line or vim.api.nvim_win_get_cursor(window)[1] - 1
self.first_line = line or (self.window and vim.api.nvim_win_get_cursor(self.window)[1] - 1 or 0)
self.finished_lines = 0
self.response = ""
self.queries = queries
Expand Down
3 changes: 2 additions & 1 deletion tests/parrot/response_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("ResponseHandler", function()
mock_vim = {
api = {
nvim_get_current_buf = stub.new().returns(1),
nvim_get_current_win = stub.new().returns(1),
nvim_create_namespace = stub.new().returns(1),
nvim_buf_set_extmark = stub.new().returns(1),
nvim_buf_is_valid = stub.new().returns(true),
Expand Down Expand Up @@ -43,7 +44,7 @@ describe("ResponseHandler", function()
it("should create a new ResponseHandler with default values", function()
local handler = ResponseHandler:new(mock_queries)
assert.are.same(1, handler.buffer)
assert.are.same(nil, handler.window)
assert.are.same(vim.api.nvim_get_current_win(), handler.window)
assert.are.same("", handler.prefix)
assert.are.same(false, handler.cursor)
assert.are.same(0, handler.first_line)
Expand Down

0 comments on commit f2cbfc5

Please sign in to comment.