fix: autochdir for custom terminals (#553)

* fix: autochdir for custom terminals

* refactor: use ternary expression

can do it like this when the variable is now assigned outside of this block
This commit is contained in:
Turiiya 2024-04-19 13:33:12 +02:00 committed by GitHub
parent fef08f32b9
commit dca1c80fb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -485,7 +485,8 @@ end
---@param size number?
---@param direction string?
function Terminal:open(size, direction)
self.dir = _get_dir(self.dir)
local cwd = fn.getcwd()
self.dir = _get_dir(config.autochdir and cwd or self.dir)
ui.set_origin_window()
if direction then self:change_direction(direction) end
if not self.bufnr or not api.nvim_buf_is_valid(self.bufnr) then
@ -496,10 +497,7 @@ function Terminal:open(size, direction)
local ok, err = pcall(opener, size, self)
if not ok and err then return utils.notify(err, "error") end
ui.switch_buf(self.bufnr)
if config.autochdir then
local cwd = fn.getcwd()
if self.dir ~= cwd then self:change_dir(cwd) end
end
if config.autochdir and self.dir ~= cwd then self:change_dir(cwd) end
end
ui.hl_term(self)
-- NOTE: it is important that this function is called at this point. i.e. the buffer has been correctly assigned