Skip to content

Commit 80526dc

Browse files
Fix: Skip showing terminal if buffer is no longer valid or not exists.
Closes #28
1 parent adc2201 commit 80526dc

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
## [Unreleased]
66

77
- Fix: Correctly center floating terminal when no borders are used.
8+
- Fix: Skip showing terminal if buffer is no longer valid or it doesn't exist.
89
- Set terminal window as `nolist`.
910
- Add `fixed_height` & `fixed_width` options to control whether terminal size should be preserved on new splits.
1011
- Do not ignore wildcard patterns when expanding `dir`.

lua/ergoterm/instance/open.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434
---@param term Terminal
3535
---@param layout layout?
3636
function M.show(term, layout)
37-
if not M.is_open(term) then
37+
if not M.is_open(term) and term._state.bufnr and vim.api.nvim_buf_is_valid(term._state.bufnr) then
3838
layout = layout or term._state.layout
3939
local window = nil
4040
if vim.tbl_contains(NEW_WINDOW_LAYOUTS, layout) then

spec/ergoterm/instance/open_spec.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ describe(".open", function()
112112
assert.equal("right", win_config.split)
113113
end)
114114

115+
it("does nothing if buffer is missing", function()
116+
local term = Terminal:new():start()
117+
term:cleanup()
118+
119+
local ok = pcall(function()
120+
open.show(term)
121+
end)
122+
123+
assert.is_true(ok)
124+
assert.is_nil(term:get_state("window"))
125+
end)
126+
115127
it("errors if layout is invalid", function()
116128
local term = Terminal:new()
117129

0 commit comments

Comments
 (0)